解決 No qualifying bean of type 問題
思路:
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
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 {