These days, while studying the spring boot framework, the early spring boot and mybaits combined, my code to live in the service at the action level did not complain, but when the service injected the MyBatis Mapper interface, the following error was reported.
Java.lang.Object.wait (Native method) Java.lang.ref.ReferenceQueue.remove (referencequeue.java:143) Com.mysql.jdbc.AbandonedConnectionCleanupThread.run (abandonedconnectioncleanupthread.java:43) [ERROR] 09:51:11 O.s.boot.springapplication => application startup failed Org.springframework.beans.factory.BeanCreationException
: Error creating Bean with Name ' Iuserservice ': Injection of autowired dependencies failed; Nested exception is org.springframework.beans.factory.BeanCreationException:Could not Autowire field:private Com.company.test.dao.UserMapper Com.company.test.service.impl.UserServiceImpl.userMapper; Nested exception is Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [
Com.company.test.dao.UserMapper] found for dependency:expected at least 1 beans which qualifies as autowire for
This dependency. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (Required=true)} at Org.springframework.beaNs.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ( autowiredannotationbeanpostprocessor.java:334) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1214) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:543) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean ( abstractautowirecapablebeanfactory.java:482) at org.springframework.beans.factory.support.abstractbeanfactory$1. GetObject (abstractbeanfactory.java:306) at Org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton ( defaultsingletonbeanregistry.java:230) at Org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (abstractbeanfactory.java:302) at Org.springframework.beans.factory.support.AbstractBeanFactory.getBean (abstractbeanfactory.java:197) at orG.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons ( defaultlistablebeanfactory.java:772) at Org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization ( abstractapplicationcontext.java:839) at Org.springframework.context.support.AbstractApplicationContext.refresh ( abstractapplicationcontext.java:538) at Org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh ( embeddedwebapplicationcontext.java:118) at Org.springframework.boot.SpringApplication.refresh ( springapplication.java:766) at Org.springframework.boot.SpringApplication.createAndRefreshContext ( springapplication.java:361) at Org.springframework.boot.SpringApplication.run (springapplication.java:307) at Org.springframework.boot.SpringApplication.run (springapplication.java:1191) at Org.springframework.boot.SpringApplication.run (springapplication.java:1180) at Com.company.test.Application.main
(application.java:19) caused By:org.spriNgframework.beans.factory.BeanCreationException:Could not Autowire field:private com.company.test.dao.UserMapper Com.company.test.service.impl.UserServiceImpl.userMapper; Nested exception is org.springframework.beans.factory. Nosuchbeandefinitionexception:no qualifying Bean of type [com.company.test.dao.UserMapper] found for dependency: Expected at least 1 beans which qualifie s as Autowire candidate for this dependency. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (Required=true)} at
Org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject (autowiredannotationbeanpostprocessor.java:573) at Org.springframework.beans.factory.annotation.InjectionMetadata.inject (injectionmetadata.java:88) at Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ( autowiredannotationbeanpostprocessor.java:331)
Error tips
The Usermapper interface did not implement the class, and then I saw my spring and MyBatis jar package also introduced, configuration also configured, how to report such a mistake.
Workaround:
Then I found the main boot method of spring boot, which scanned the child package class under the current package, and my base project and test project package had the wrong path, and when I modified the package path,
Spring boot can be automatically scanned into the configuration file, Mapper also injected.