天天看點

解決IDEA中 Could not autowire. No beans of 'xxxx' type found 的錯誤提示前言解決方案其他可能原因

前言

近段時間,轉到IDEA來開發公司項目。但是經常會出現Could not autowire. No beans of ‘xxxx’ type found的錯誤提示。

這個錯誤提示并不會産生影響,程式的編譯和運作都是沒有問題的。

但是對于強迫症而言,紅色的錯誤提示是不可容忍的。是以開始着手解決

解決IDEA中 Could not autowire. No beans of 'xxxx' type found 的錯誤提示前言解決方案其他可能原因

解決方案

其實出現這種問題的原因基本都是IntellijIDEA本身工具的問題。解決方案主要包括:

1)不管他

表示強迫症真的是受不了

2) 修改注解

@Autowired(required = false)           

3) 使用@Resource注解

@Resource           

4) 修改IDEA配置

修改IDEA設定,降低Autowired檢測的級别,将Severity的級别由之前的error改成warning或其它可以忽略的級别。

解決IDEA中 Could not autowire. No beans of 'xxxx' type found 的錯誤提示前言解決方案其他可能原因

其他可能原因

1. 導入包的依賴異常

第二個可能的原因是我們導入@Service包的時候導入包錯誤造成的

錯誤導包

import com.alibaba.dubbo.config.annotation.Service;
           

正确的包應該是下面這個:

import org.springframework.stereotype.Service;           

繼續閱讀