思路:
1 检查是否添加了对应注解
2 检查配置是否正确,扫描包名, 类名及id是否正确
一 . 传统SSM项目
ssm项目,出现“No qualifying bean of type found for dependency ***”错误,最后定位到该bean,仔细检查,
<context:component-scan base-package=
- <context:component-scan base-package="com.ayh.order" use-default-filters="false">
- <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
- </context:component-scan>
再如:在applicationContext-Service.xml中,有没有配置所注入service
- applicationContext-Service.xml:
- <bean id="orderServiceImp" class="com.it.service.imp.OrderServiceImp"></bean>
如:jpaj的jar包冲突
二 . spring boot项目
@Autowired - No qualifying bean of type found for dependency
1 . 主要就是检查是否在对应的类上添加了注解如:@Controller @Service @Reporsitry @Component
2 . 启动类所在的位置是否在其他被扫描类的包的前面
如:启动类要在order包.其他类在下一级包
以下为根据具体选用情况而定, 多用优先级的顺序问题
1 .是否使用在具体mapper上有到 @Mapper
2 . 是否使用在application文件中
- mybatis:
- type-aliases-package: com.ayh.order.pojo
- mapper-locations: com.ayh.order.mappers
3 .是否使用在启动类上用到了@MapperScan(value="com.ayh.order.mappers")
- @SpringBootApplication
- @EnableDiscoveryClient
- @EnableFeignClients
- @MapperScan(value = "com.ayh.order.mappers")
- public class OrderApplication {
联系客服