Just came in early this morning to write code, and then yesterday used Mapperscannerconfigurer to sweep the package. To help free from the DAO layer (you just need to define the interface). As a result, a bug was encountered. The exception contents are as follows:
java.lang.IllegalStateException:Failed to load ApplicationContext at Org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext ( defaultcacheawarecontextloaderdelegate.java:124) at Org.springframework.test.context.support.DefaultTestContext.getApplicationContext (defaulttestcontext.java:83) At Org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies ( dependencyinjectiontestexecutionlistener.java:117) at Org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance ( dependencyinjectiontestexecutionlistener.java:83) at Org.springframework.test.context.TestContextManager.prepareTestInstance (testcontextmanager.java:228) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest (springjunit4classrunner.java:230) at Org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall ( springjunit4classrunner.java:289) at ORG.JUNIT.INTERNAL.RUNNERS.MOdel. Reflectivecallable.run (Reflectivecallable.java:12) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock (springjunit4classrunner.java:291) At Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:249) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:89) at Org.junit.runners.parentrunner$3.run (parentrunner.java:238) at Org.junit.runners.parentrunner$1.schedule ( parentrunner.java:63) at Org.junit.runners.ParentRunner.runChildren (parentrunner.java:236) at org.junit.runners.parentrunner.access$000 (parentrunner.java:53) at Org.junit.runners.parentrunner$2.evaluate ( parentrunner.java:229) at Org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate ( RUNBEFORETESTCLASSCALLBACKS.JAVA:61) at Org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate ( RUNAFTERTESTCLASSCALLBACKS.JAVA:70) at Org.junit.runners.ParEntrunner.run (parentrunner.java:309) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run ( springjunit4classrunner.java:193) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run ( junit4testreference.java:86) at Org.eclipse.jdt.internal.junit.runner.TestExecution.run (testexecution.java:38) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:459) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:675) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:382) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:192) caused by: Org.springframework.beans.factory.BeanCreationException:Error creating Bean with Name ' Brandserviceimpl ': injection of resource dependencies failed; Nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating beans with Name ' Branddao ' defined in file [E:\WorkSpAce\newbabasport\babasport\target\classes\cn\ilxy\dao\product\branddao.class]: Unsatisfied Dependency expressed Through Bean property ' sqlsessionfactory ': Error creating Beans with Name ' sqlsessionfactory ' defined in file [E:\WorkSpace \newbabasport\babasport\target\classes\config\mybatis.xml]: Invocation of Init method failed; Nested exception is org.apache.ibatis.type.TypeException:The alias ' Brandquery ' was already mapped to the value ' CN.ILXY.Q Uery. Brandquery '.; Nested exception is org.springframework.beans.factory.BeanCreationException:Error creating beans with Name ' Sqlsessionfactory ' defined in file [E:\WorkSpace\NewBaBaSport\BaBaSport\target\classes\config\mybatis.xml]: Invocation of Init method failed; Nested exception is org.apache.ibatis.type.TypeException:The alias ' Brandquery ' was already mapped to the value ' CN.ILXY.Q Uery. Brandquery '. At Org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues ( Commonannotationbeanpostprocessor.java:311) 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.test.context.support.AbstractGenericContextLoader.loadContext ( abstractgenericcontextloader.java:125) at Org.springframework.test.context.support.AbstractGenericContextLoader.loadContext ( ABSTRACTGENERICCONTEXTLOADER.JAVA:60) at Org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading ( ABSTRACTDELEGATINGSMARTCONTEXTLOADER.JAVA:109) at Org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext ( abstractdelegatingsmartcontextloader.java:261) at Org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal ( DEFAULTCACHEAWARECONTEXTLOADERDELEGATE.JAVA:98) at Org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.Loadcontext (defaultcacheawarecontextloaderdelegate.java:116) ... More caused by:org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating beans with Name ' Branddao ' defined in file [E:\WorkSpace\NewBaBaSport\BaBaSport\target\classes\cn\ilxy\dao\product\BrandDao.class]: Unsatisfied dependency expressed through Bean property ' sqlsessionfactory ': Error creating Beans with Name ' Sqlsessionfacto Ry ' defined in file [E:\WorkSpace\NewBaBaSport\BaBaSport\target\classes\config\mybatis.xml]: Invocation of Init method Failed Nested exception is org.apache.ibatis.type.TypeException:The alias ' Brandquery ' was already mapped to the value ' CN.ILXY.Q Uery. Brandquery '.; Nested exception is org.springframework.beans.factory.BeanCreationException:Error creating beans with Name ' Sqlsessionfactory ' defined in file [E:\WorkSpace\NewBaBaSport\BaBaSport\target\classes\config\mybatis.xml]: Invocation of Init method failed; Nested exception is Org.apache.ibatis.type.TypeException:The alIAS ' Brandquery ' is already mapped to the value ' cn.ilxy.query.BrandQuery '. At Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType ( abstractautowirecapablebeanfactory.java:1307) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1199) 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:202) at Org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource ( COMMONANNOTATIONBEANPOSTPROCESSOR.JAVA:512) at Org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource ( commonannotationbeanpostprocessor.java:486) at Org.springframework.context.annotation.commonannotationbeanpostprocessor$resourceelement.getresourcetoinject ( commonannotationbeanpostprocessor.java:615) at org.springframework.beans.factory.annotation.injectionmetadata$ Injectedelement.inject (injectionmetadata.java:169) at Org.springframework.beans.factory.annotation.InjectionMetadata.inject (injectionmetadata.java:88) at Org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues ( commonannotationbeanpostprocessor.java:308) ... caused by:org.springframework.beans.factory.BeanCreationException:Error creating bean with Name ' Sqlsessionfactory ' defined inFile [E:\WorkSpace\NewBaBaSport\BaBaSport\target\classes\config\mybatis.xml]: Invocation of Init method failed; Nested exception is org.apache.ibatis.type.TypeException:The alias ' Brandquery ' was already mapped to the value ' CN.ILXY.Q Uery. Brandquery '. At Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean ( abstractautowirecapablebeanfactory.java:1578) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:545) 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.findAutowireCandidates ( defaultlistablebeanfactory.java:1192) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency ( defaultlistablebeanfactory.java:1116) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency ( DEFAULTLISTABLEBEANFACTORY.JAVA:1014) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType ( abstractautowirecapablebeanfactory.java:1292) ... caused By:org.apache.ibatis.type.TypeException:The alias ' brandquery ' is already mapped to the value ' Cn.ilxy.qu ery. Brandquery '. At Org.apache.ibatis.type.TypeAliasRegistry.registerAlias (typealiasregistry.java:157) at Org.apache.ibatis.type.TypeAliasRegistry.registerAlias (typealiasregistry.java:147) at Org.apache.ibatis.type.typealiasregistry.rEgisteraliases (typealiasregistry.java:136) at Org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory ( sqlsessionfactorybean.java:395) at Org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet ( sqlsessionfactorybean.java:355) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods ( abstractautowirecapablebeanfactory.java:1637) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean ( abstractautowirecapablebeanfactory.java:1574) ... More you reader attention, and I see mybatis so many unusual experience, generaljava.lang.IllegalStateException:Failed to load ApplicationContext exceptionThe information is on the top, most of the configuration file you wrote is a problem, this time I am also. I also reported this error when I used the JUnit test without invoking any business logic methods. The exception information is that spring in the sweep package, has found that the Brandquery alias and the Cn.ilxy.query.BrandQuery class has formed a corresponding relationship, in the process of continuing the scan found a class named Brandquery, so reported this exception. Later I looked at the project directory (pictured below): you reader see. No, there are two entity classes named Brandquery. So the exception is reported. Solution: Each class name must be unique. No duplicate name. I believe you reader know how to change it. Change the class name on the line. Share out, hope for you program ape to help, less detours. Since the choice of the distance, it should be trials and hardships. Give the best to the future