SpringBoot: Field xxx in xxx required a bean of type 'xxx' that could not be found.

SpringBoot自动注入报了如下错误

 、

原因是我这个模块依赖另一个模块里面的被Spring管理的类,但是不在同一包下面,

 并且启动类不是在根包下面,所以就导致了springboot启动的时候扫描不到,也就管理不到这个类,也就无法找到,

解决方案:

  1.SpringBoot启动类放到包的跟包下面比如每个包都包含 cn.arebirth.xx  那就放在cn.arbeirth下面

  2.设置SpringBoot扫描的包路径即可解决

猜你喜欢

转载自www.cnblogs.com/arebirth/p/springbootautowiredbasepackagepatherror.html