mybatis项目启动报错 The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
启动项目报错
2018-02-26 17:09:51,535 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testTreeDao' defined in file [/Users/jds/Documents/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeesite/WEB-INF/classes/com/thinkgem/jeesite/test/dao/TestTreeDao.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [/Users/jds/Documents/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeesite/WEB-INF/classes/spring-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [/Users/jds/Documents/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeesite/WEB-INF/classes/mappings/modules/sys/RoleDao.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 34; columnNumber: 14; The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)". at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1475) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1220) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at com.thinkgem.jeesite.modules.sys.listener.WebContextListener.initWebApplicationContext(WebContextListener.java:16) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [/Users/jds/Documents/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeesite/WEB-INF/classes/spring-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [/Users/jds/Documents/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeesite/WEB-INF/classes/mappings/modules/sys/RoleDao.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 34; columnNumber: 14; The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)". at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 25 more Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource:
'file [/Users/jds/Documents/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeesite/WEB-INF/classes/mappings/modules/sys/RoleDao.xml]';
nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.
Cause: org.xml.sax.SAXParseException; lineNumber: 34; columnNumber: 14; The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)". at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:522) at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:374) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) ... 32 more Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 34; columnNumber: 14; The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)". at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:256) at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:125) at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:86) at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:515) ... 35 more Caused by: org.xml.sax.SAXParseException; lineNumber: 34; columnNumber: 14; The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)". at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:254) ... 38 more
重点在上面代码中的标红出,指出了 RoleDao.xml的报错
The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
以上报错的意思是 元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id*,result*,association*,collection*,discriminator?)"
解决方法:
将resultMap 中各元素的顺序修改为和错误信息中属性出现的顺序( constructor , id result association .....)一致
例如
之前的xml文件中代码
1 <resultMap id="roleResult" type="Role"> 2 <id property="id" column="id" /> 3 <association property="office" javaType="Office"> 4 <id property="id" column="office.id" /> 5 <id property="name" column="office.name" /> 6 </association> 7 <result property="name" column="name" /> 8 <result property="enname" column="enname" /> 9 <result property="roleType" column="roleType" /> 10 <result property="dataScope" column="dataScope" /> 11 <result property="remarks" column="remarks" /> 12 <result property="useable" column="useable" /> 13 <result property="sysData" column="sysData" /> 24 <collection property="menuList" ofType="Menu"> 25 <id property="id" column="menuList.id" /> 26 </collection> 27 <collection property="officeList" ofType="Office"> 28 <id property="id" column="officeList.id" /> 29 </collection> 30 </resultMap> 31
解决后xml文件中的代码
1 <resultMap id="roleResult" type="Role"> 2 <id property="id" column="id" /> 3 <result property="name" column="name" /> 4 <result property="enname" column="enname" /> 5 <result property="roleType" column="roleType" /> 6 <result property="dataScope" column="dataScope" /> 7 <result property="remarks" column="remarks" /> 8 <result property="useable" column="useable" /> 9 <result property="sysData" column="sysData" /> 10 <association property="office" javaType="Office"> 11 <id property="id" column="office.id" /> 12 <id property="name" column="office.name" /> 13 </association> 14 20 <collection property="menuList" ofType="Menu"> 21 <id property="id" column="menuList.id" /> 22 </collection> 23 <collection property="officeList" ofType="Office"> 24 <id property="id" column="officeList.id" /> 25 </collection> 26 </resultMap>