1.問題
解決 No qualifying bean of type 問題
2.思路:
1 檢查是否添加了對應注解
2 檢查配置是否正確,掃描包名, 類名及id是否正確
一 . 傳統SSM項目
ssm項目,出現“No qualifying bean of type found for dependency ***”錯誤,最后定位到該bean,仔細檢查,
1 首先檢查是否在類上添加了對應的注解,如:@Controller @Service @Reporsitry @Component
2 然后檢查配置文件,發現有沒有掃描到相應的包,在配置文件中加上該包
<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>
3 是否有jar包依賴沖突
如:jpaj的jar包沖突
二 . spring boot項目
@Autowired - No qualifying bean of type found for dependency
1 . 主要就是檢查是否在對應的類上添加了注解如:@Controller @Service @Reporsitry @Component
我的是在ReturnCycleReportJobHandler這里沒有加入:@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 {
原文:https://blog.csdn.net/u010565545/article/details/100066824