使用 IntelliJ IDEA 开发 Spring Boot 项目。在自动注入时,会出现红色波浪线的错误提示。如图:
![](/2020/04/%E8%A7%A3%E5%86%B3IntelliJ-IDEA-Could-not-autowire-No-beans-of-UserMapper-type-found/could-not-autowire.png)
如果代码正确,能够正常运行。那我们可以通过如下两种方法解决。
添加@Repository注解
查看一下是不是 Mapper
类忘了写 @Repository
注解。
设置IDEA
进入 Editor
-> Inspections
-> Spring
-> Spring Core
-> Autowiring for Bean Class
把选中的勾去掉就可以了。
![](/2020/04/%E8%A7%A3%E5%86%B3IntelliJ-IDEA-Could-not-autowire-No-beans-of-UserMapper-type-found/autowire-settings.png)