写在前面
在使用SPRINGBOOT整合MYBATIS的时候,使用@Autowired自动注入’XXXMapper’时,就会出现Could not autowire. No beans of ‘XXXMapper’ type found.的错误,提示不能够自动注入BEAN。
启动类已添加注解@MapperScan(“com.hadoopx.mallx.mapper”),程序是可以正常运行的。
解决方案
File -> Settings -> Inspections -> Spring -> Spring Core -> Code -> Autowiring foe Bean Class
将’Error’改为’Warning’。

问题原因
IDEA可以识别SPRING的上下文环境,能够识别SPRING的注解@Autowired,而@Mapper和@MapperScan注解是Mybatis的,IDEA无法识别,所以IDEA遇到这种情况会报错。
在使用SpringBoot整合Mybatis时,可能会遇到@Autowired自动注入Mapper失败的问题,IDEA报错'Could not autowire. No beans of 'XXXMapper' type found.'。尽管在启动类已添加@MapperScan注解,但IDEA仍然无法识别。解决方法是在IDEA的设置中将'Autowiring for Bean Class'的错误级别改为警告。问题源于IDEA只能识别Spring注解,无法识别Mybatis的@Mapper和@MapperScan。
4192

被折叠的 条评论
为什么被折叠?



