springboot 整合 mybatis 报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

 报错如下:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.****.mybatis.springboot.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    ... 29 common frames omitted

 

解决方法:

在启动类中加入dao层mapper接口文件扫描注解

@MapperScan("mapper接口文件包路径");

 

 springboot 整合 mybatis 报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException_第1张图片

 遇到这种首先各个路径是否配置正确:

例如xml中的

 

以及扫描配置:

 

springboot 整合 mybatis 报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException_第2张图片

 最后检查jar包是否正确:

       
            org.mybatis
            mybatis
            3.4.4
        

        
            org.mybatis
            mybatis-spring
            1.3.1
        

 

你可能感兴趣的:(springboot)