IntelliJ Idea解决Could not autowire. No beans of 'xxxx' type found的错误提示

1.问题

在IDEA的springboot项目中会遇到“Could not autowire. No beans of 'xxxx' type found”这样的错误提示,但是该错误提示不会影响项目的编译和运行,就是看着难受。,如图所示

IntelliJ Idea解决Could not autowire. No beans of 'xxxx' type found的错误提示

2.原因

1.IntellijIDEA本身工具的问题;

2.导入@Service包的时候导入包错误造成的;

3.解决方案

1.根据第一种原因,降低Autowired检测的级别,将Severity的级别由之前的error改成warning或其它可以忽略的级别。

IntelliJ Idea解决Could not autowire. No beans of 'xxxx' type found的错误提示

2.对于第二种原因则是导入正确的包

首先我们来看下最容易导入的错误包,如下所示:

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

正确的如下:import org.springframework.stereotype.Service;

收集到的其他解决方案:

1.在mapper文件上加@Repository注解,这是从spring2.0新增的一个注解,用于简化 Spring 的开发,实现数据访问

2.在mapper文件上加@Component注解,把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class="">

我现在遇到的是第一种原因,我觉得几种方法好像都会有效,但具体什么原因不清楚,还在学习中

参考:IntelliJ Idea解决Could not autowire. No beans of 'xxxx' type found的错误提示