解决 No qualifying bean of type 问题

解决 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 {
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sh_c_1314

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值