【Spring】@Autowired报错Could not autowire. No beans of xxx

问题描述
开发工具采用的是IDEA,写了一个DAO接口,在service中注入时,报错:Could not autowire. No beans of xxx。

问题原因
原因在于DAO接口添加的@Mapper并不是Spring的注解,而是ibatis的注解,并没有声明这个DAO接口作为Spring的Bean,因此Spring不能进行管理,导致注入报错。

解决办法
只需在DAO接口加上@Component 或者 @Repository(@Repository实际上也包含了@Component注解)注解声明为Spring的Bean即可。


--------------------- 
作者:Mr_EvanChen 
来源:CSDN 
原文:https://blog.csdn.net/Mr_EvanChen/article/details/84035445 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/CatEatApple/article/details/88599217