0
点赞
收藏
分享

微信扫一扫

【springboot】自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration的问题

皮皮球场 2022-02-26 阅读 116

Consider defining a bean of type ‘com.example.ch2_1_1.repository.TodoRepository’ in your configuration.
我写的几个类
实体
todo实体类
接口
接口

控制类
控制类

但运行时出错spring给建议为Consider defining a bean of type ‘xxx‘ in your configuration

英文提示为在配置中找不到一个指定自动注入类型的bean,在正常情况下@Component注解的类会自动被Spring扫描到生成Bean注册到Spring容器中,出错原因在于它没扫描到,原因又在启动类上。
@SpringBootApplication的效果包含@Component,在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动注册为Bean的@Service@Controller和@ Repository。
之前我将接口与对应实现类放在了与控制器所在包的同一级目录下,这样的注解自然是无法被识别的
最后改成了这样的文件格式
在这里插入图片描述

举报

相关推荐

0 条评论