Server startup error when using MyBatis
Error Recurrence
Severity: Exception sending context initialized event to listener instance of class Org.springframework.web.context.ContextLoad Erlistener Org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating Bean with Name ' Userserviceimpl ': Unsatisfied dependency expressed through field ' Usermapper '; Nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating beans with Name ' Usermapper ' defined in file [E:\study\apache-tomcat-7.0.73\webapps\tongxuelu\WEB-INF\classes\org\jxnd\tongxuelu\ Dao\usermapper.class]: Unsatisfied dependency expressed through Bean property ' sqlsessionfactory '; Nested exception is org.springframework.beans.factory.BeanCreationException:Error creating beans with Name ' Sessionfactory ' defined in class path resource [Applicationcontext.xml]: Invocation of Init method failed; Nested exception is org.springframework.core.NestedIOException:Failed to parse mapping resource: ' File [E:\study\ Apache-tomcat-7.0.73\webapps\tongxuElu\web-inf\classes\mapper\usermapper.xml] '; Nested exception is Org.apache.ibatis.builder.BuilderException:Error parsing Mapper XML. Cause:java.lang.IllegalArgumentException:Result Maps Collection already contains value for Org.jxnd.tongxuelu.dao.UserMapper.BaseResultMap at Org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject (autowiredannotationbeanpostprocessor.java:588) at Org.springframework.beans.factory.annotation.InjectionMetadata.inject (injectionmetadata.java:88) at Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ( autowiredannotationbeanpostprocessor.java:366) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1264) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:553) at Org.springframework. Beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (Abstractautowirecapablebeanfactory.java
: 483) 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:761) at Org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization ( abstractapplicationcontext.java:866) at Org.springframework.context.support.AbstractApplicationContext.refresh ( abstractapplicationcontext.java:542) at Org.springframework.web.context.ContextLoader.configurEandrefreshwebapplicationcontext (contextloader.java:443) at Org.springframework.web.context.ContextLoader.initWebApplicationContext (contextloader.java:325) at Org.springframework.web.context.ContextLoaderListener.contextInitialized (contextloaderlistener.java:107) at Org.apache.catalina.core.StandardContext.listenerStart (standardcontext.java:5118) at Org.apache.catalina.core.StandardContext.startInternal (standardcontext.java:5634) at Org.apache.catalina.util.LifecycleBase.start (lifecyclebase.java:145) at Org.apache.catalina.core.ContainerBase.addChildInternal (containerbase.java:899) at Org.apache.catalina.core.ContainerBase.addChild (containerbase.java:875) at Org.apache.catalina.core.StandardHost.addChild (standardhost.java:652) at Org.apache.catalina.startup.HostConfig.deployDirectory (hostconfig.java:1260) at Org.apache.catalina.startup.hostconfig$deploydirectory.run (hostconfig.java:2002) at Java.util.concurrent.executors$runnableadapter.call (Unknown Source) at Java.util.conCurrent. Futuretask.run (Unknown source) at Java.util.concurrent.ThreadPoolExecutor.runWorker (Unknown source) at Java.util.concurrent.threadpoolexecutor$worker.run (Unknown source) at Java.lang.Thread.run (Unknown source) caused by : Org.springframework.beans.factory.UnsatisfiedDependencyException:Error creating Bean with Name ' usermapper ' defined in file [E:\study\apache-tomcat-7.0.73\webapps\tongxuelu\WEB-INF\classes\org\jxnd\tongxuelu\dao\UserMapper.class ]: Unsatisfied dependency expressed through Bean property ' sqlsessionfactory '; Nested exception is org.springframework.beans.factory.BeanCreationException:Error creating beans with Name ' Sessionfactory ' defined in class path resource [Applicationcontext.xml]: Invocation of Init method failed; Nested exception is org.springframework.core.NestedIOException:Failed to parse mapping resource: ' File [E:\study\ Apache-tomcat-7.0.73\webapps\tongxuelu\web-inf\classes\mapper\usermapper.xml] '; Nested exception is Org.apache.ibatis.builder.BuildErexception:error parsing Mapper XML. Cause:java.lang.IllegalArgumentException:Result Maps Collection already contains value for Org.jxnd.tongxuelu.dao.UserMapper.BaseResultMap at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType ( abstractautowirecapablebeanfactory.java:1357) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1249) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:553) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean ( abstractautowirecapablebeanfactory.java:483) 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.beans.factory.config.DependencyDescriptor.resolveCandidate (dependencydescriptor.java:208) At Org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency ( defaultlistablebeanfactory.java:1138) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency ( defaultlistablebeanfactory.java:1066) at Org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject (autowiredannotationbeanpostprocessor.java:585) ... caused by:org.springframework.beans.factory.BeanCreationException:Error creating bean with Name ' Sessionfactory ' defined in class path resource [Applicationcontext.xml]: Invocation of Init method failed; Nested exception is org.springframework.core.NestedIOException: Failed to parse Mapping resource: ' File [E:\study\apache-tomcat-7.0.73\webapps\tongxuelu\WEB-INF\classes\mapper\ Usermapper.xml] '; Nested exception is Org.apache.ibatis.builder.BuilderException:Error parsing Mapper XML. Cause:java.lang.IllegalArgumentException:Result Maps Collection already contains value for Org.jxnd.tongxuelu.dao.UserMapper.BaseResultMap at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean ( abstractautowirecapablebeanfactory.java:1628) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:555) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean ( abstractautowirecapablebeanfactory.java:483) 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.su Pport. Abstractbeanfactory.dogetbean (abstractbeanfactory.java:302) at Org.springframework.beans.factory.support.AbstractBeanFactory.getBean (abstractbeanfactory.java:202) at
Org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate (dependencydescriptor.java:208) At Org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency ( defaultlistablebeanfactory.java:1138) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency ( defaultlistablebeanfactory.java:1066) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType ( abstractautowirecapablebeanfactory.java:1342) ... caused by:org.springframework.core.NestedIOException:Failed to parse mapping resource: ' File [E:\study\apache-t Omcat-7.0.73\webapps\tongxuelu\web-inf\classes\mapper\usermapper.xml] '; Nested exception is org.apache.ibatis.builder.BuilderExceptIon:error parsing Mapper XML. Cause:java.lang.IllegalArgumentException:Result Maps Collection already contains value for Org.jxnd.tongxuelu.dao.UserMapper.BaseResultMap at Org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory (sqlsessionfactorybean.java:522) at Org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet (sqlsessionfactorybean.java:381) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods ( abstractautowirecapablebeanfactory.java:1687) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean ( abstractautowirecapablebeanfactory.java:1624) ... caused By:org.apache.ibatis.builder.BuilderException:Error parsing Mapper XML. Cause:java.lang.IllegalArgumentException:Result Maps Collection already contains value for Org.jxnd.tongxuelu.dao.UserMapper.BaseResultMap at Org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement (xmlmapperbuilder.java:120) at Org.apaChe.ibatis.builder.xml.XMLMapperBuilder.parse (xmlmapperbuilder.java:92) at Org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory (sqlsessionfactorybean.java:520) ... caused By:java.lang.IllegalArgumentException:Result Maps collection already contains value for Org.jxnd.tongxuel
U.dao.usermapper.baseresultmap at Org.apache.ibatis.session.configuration$strictmap.put (Configuration.java:859) At Org.apache.ibatis.session.configuration$strictmap.put (configuration.java:831) at Org.apache.ibatis.session.Configuration.addResultMap (configuration.java:613) at Org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap (mapperbuilderassistant.java:214) at Org.apache.ibatis.builder.ResultMapResolver.resolve (resultmapresolver.java:47) at Org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement (xmlmapperbuilder.java:285) at Org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement (xmlmapperbuilder.java:252) at Org.apache.ibatis.builder.xml.XMLMapperBuilder.reSultmapelements (xmlmapperbuilder.java:244) at Org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement (xmlmapperbuilder.java:116) ...
More
Exception Troubleshooting
Locate the Usermapper.xml file based on the error message, and finally find that the first 400 lines and the last 400 lines of code are identical, such as:
Workaround
Cause: There is a duplicate object in the XML file, and keeping the name not the same can start normally. Because I used reverse engineering again to generate the Mapper interface and the XML file, I forgot to delete the original XML file, the new generation and the old old duplicate.
So when we create a new ID query method, there may also be a rename condition that causes such an error, remember here
FIX: Delete duplicate named ID or delete XML file reverse engineer