问题场景,我在service层的实现类中  进行装配dao层对象时,提示Could not autowired. no beans of "XXX" type found.

没有装配到,肯定不行啊,有问题。如图:

Idea中 装配对象时(@Autowired) 出现 Could not autowire. no beans of "XXX" type found

有的大牛说这个idea的纠错机制对spring的某些配置没有很好的支持。

可以不用管,但是程序员一般都是有强迫症的,还是想要解决掉它。

网上常见的两个方向,我简单提一下。想要详细了解的csdn搜一大堆。

第一种

降低Autowired的检测级别,将Serverity的级别由之前的error改成warning或者其他可以忽略的级别。如图:

Idea中 装配对象时(@Autowired) 出现 Could not autowire. no beans of "XXX" type found

第二种

可能是你加@Service注解时,导入包有误。

正确的包是:

org.springframework.stereotype.Service

最后说一下我的终极解决办法:那就是在dao层的类上加@Repository注解,就ok了。在去看dao层,就没有那个提示了。

该注解时从spring2.0开始增加的注解,用于简化spring的开发,将数据访问层的类标识为SpringBean。

 

 

 

相关文章:

  • 2021-10-13
  • 2021-06-21
  • 2021-10-16
  • 2021-08-13
  • 2021-11-22
  • 2021-05-31
  • 2021-06-29
  • 2021-08-11
猜你喜欢
  • 2021-12-10
  • 2021-05-20
  • 2021-07-18
  • 2021-04-19
  • 2022-12-23
  • 2021-09-16
  • 2021-05-15
相关资源
相似解决方案