
【springboot】自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration的问题
Consider defining a bean of type ‘com.example.ch2_1_1.repository.TodoRepository’ in your configuration. 我写的几个类 实体 接口
控制类
但运行时出错spring给建议为Consider defining a bean of type ‘xxx‘ in your configuration
英文提示为在配置中找不到一个指定自动注入类型的bean,在正常情况下@Component注解的类会自动被Spring扫描到生成Bean注册到Spring容器中,出错原因在于它没扫描到,原因又在启动类上。 @springbootApplication的效果包含@Component,在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动注册为Bean的@Service@Controller和@ Repository。 之前我将接口与对应实现类放在了与控制器所在包的同一级目录下,这样的注解自然是无法被识别的 最后改成了这样的文件格式
实践证明不可以,别这样干了给拿出来,因为我还要用Swagger
👁️ 阅读量:0
© 版权声明:本文《【springboot】自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration的问题》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686556986a291299.html。