一、报错
报错如下:
Could not autowire. No beans of 'XXMapper' type found.
Inspection info:Checks autowiring problems in a bean class.
在Idea的spring工程里,经常会遇到Could not autowire. No beans of 'xxxx' type found的错误提示。这个红色的错误提示对程序的编译和运行都不会产生影响
二、原因
导致原因:
原因可能有两个
第一个是IntellijIDEA本身工具的问题;spring auto scan配置,在编辑情况下,无法找不到对应的bean,于是提示找不到对应bean的错误
第二个便是我们导入@Service包的时候导入包错误造成的
三、解决办法
针对第一种原因,解决办法是:降低Autowired检测的级别
菜单---->设置---->Inspections---->Spring---->Spring Core---->Code,将Severity的级别由之前的error改成warning或其它可以忽略的级别
针对第二种原因,导入正确的包
正确的包应该是下面这个
import org.springframework.stereotype.Service;
最容易导入的错误包,如下所示:
import com.alibaba.dubbo.config.annotation.Service;