解决 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 {
发布了20 篇原创文章 · 获赞 24 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/u010565545/article/details/100066824