2020-08-15 18:10:46.274 ERROR 12608 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@4f18837a] to prepare test instance [com.xiaohu.crud.MybatisTest@44c13103]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.xiaohu.crud.MybatisTest': Unsatisfied dependency expressed through field 'smbmsBillMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xiaohu.crud.dao.SmbmsBillMapper' 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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
这个问题是因为springboot没有识别dao层,需要在application引导类上面配置一个@MapperScan(value = “com.xxx.dao”); value里面对应的就是你dao层的包名,也可以直接在对应的dao接口层写注解@Mapper,只是如果有很多歌dao接口类,这样写比较重复麻烦罢了