写在前面
在使用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遇到这种情况会报错。