解决idea提示不能自动注入的问题(Could not autowire. No beans of 'xxx' type found)

1、起因

idea中提示Could not autowire. No beans of ‘TempMapper’ type found.,大致翻译下来就是 ‘不能自动装配,这个xxx的bean找不到’

2、过程

1.经过检查下来,发现自己的配置文件没错,mybatis的别名,MapperScan注解也都加了,很纳闷,于是果断百度,百度几个文档下来,都是治标不治本的方法,修改ide的设置,把红线设置成黄线,这是要给谁障眼法?
解决idea提示不能自动注入的问题(Could not autowire. No beans of 'xxx' type found)_第1张图片

3、解决

mapper接口中加@Repository这个注解,实际上你加@Component、…也是可以的,都是代表一个可被spring装配的组件,说到这里就在复习下spring的几个注解吧:
@Component
@Service
@Repository
@Controller
@RestController
实际上@Component是个最基本的注解,因为我提到的几个注解源码里面都是含有@Component。

你可能感兴趣的:(JavaWeb)