Field XXX in XXXX required a bean of type XXXX that could not be found

Posted zhangxj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Field XXX in XXXX required a bean of type XXXX that could not be found相关的知识,希望对你有一定的参考价值。

这个报错的意思是:没有找到相应的bean。

出现这个情况我遇到了两种:

1.spring没有扫描到相应的bean。

   原因是springboot项目启动,只有@SpringBootApplication 所在的包被被扫描,如果有其他需要扫描的包,需要显式写明:

@SpringBootApplication
@MapperScan({"cn.jhxcom.web.demo.mapper",
    "com.baomidou.mybatisplus.samples.quickstart.mapper",
    "cn.jhxcom.project.system.user.mapper",
    })
public class HaoWebDemoApplication {...}

 这样就可以扫描到了。

 但是需要扫描的包很多的话,这样的方式显然不好,所以最好的方式是把@SpringBootApplication 所在类放在其他包的上层。

 

2.加相应的注释。在注入的时候报这个错误,应该是被注入的对象类上没有如:@Service 的注解。






以上是关于Field XXX in XXXX required a bean of type XXXX that could not be found的主要内容,如果未能解决你的问题,请参考以下文章

报错“Field pet in XXX.HelloController required a bean of type ‘XXX.Pet‘ that could not be found.“(代码片段

解决Field xxService in x.controller.x required a bean of type ‘x.service.x‘ that could no be found的方法

解决Field xxService in x.controller.x required a bean of type ‘x.service.x‘ that could no be found的方法

解决Field xxService in x.controller.x required a bean of type ‘x.service.x‘ that could no be found的方法

解决Field xxService in x.controller.x required a bean of type ‘x.service.x‘ that could no be found的方法

springboot 报错Field XXX required a bean of type XXX that could not be found.