org.xml.sax.SAXParseException 文档根元素 "mapper" 必须匹配 DOCTYPE 根 "configuration"

版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用*转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/50317239

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in file [D:\apache-tomcat-8.0.22\webapps\xinghe-platform-web\WEB-INF\classes\spring\applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘URL [jar:file:/D:/apache-tomcat-8.0.22/webapps/xinghe-platform-web/WEB-INF/lib/xinghe-base-0.0.1-SNAPSHOT.jar!/com/xinghe/edu/auth/model/mapper/AuthChildrenGroupMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
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.AbstractBeanFactory1.getObject(AbstractBeanFactory.java:303)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:743)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)atcom.auth.spring.listener.SpringLoaderListener.contextInitialized(SpringLoaderListener.java:24)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)atorg.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1399)atjava.util.concurrent.FutureTask.run(UnknownSource)atjava.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)atjava.util.concurrent.ThreadPoolExecutorWorker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘URL [jar:file:/D:/apache-tomcat-8.0.22/webapps/xinghe-platform-web/WEB-INF/lib/xinghe-base-0.0.1-SNAPSHOT.jar!/com/xinghe/edu/auth/model/mapper/AuthChildrenGroupMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:468)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:343)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
… 22 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:259)
at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:125)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:78)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:464)
… 25 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImplContentDriver.scanRootElementHook(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImplFragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImplPrologDriver.next(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(UnknownSource)atcom.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(UnknownSource)atcom.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(UnknownSource)atcom.sun.org.apache.xerces.internal.parsers.XMLParser.parse(UnknownSource)atcom.sun.org.apache.xerces.internal.parsers.DOMParser.parse(UnknownSource)atcom.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(UnknownSource)atorg.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:257)28more14:07:20,853ERRORContextLoader:331Contextinitializationfailedorg.springframework.beans.factory.BeanCreationException:ErrorcreatingbeanwithnamesqlSessionFactorydefinedinfile[D:\apachetomcat8.0.22\webapps\xingheplatformweb\WEBINF\classes\spring\applicationContextdao.xml]:Invocationofinitmethodfailed;nestedexceptionisorg.springframework.core.NestedIOException:Failedtoparsemappingresource:URL[jar:file:/D:/apachetomcat8.0.22/webapps/xingheplatformweb/WEBINF/lib/xinghebase0.0.1SNAPSHOT.jar!/com/xinghe/edu/auth/model/mapper/AuthChildrenGroupMapper.xml];nestedexceptionisorg.apache.ibatis.builder.BuilderException:Errorcreatingdocumentinstance.Cause:org.xml.sax.SAXParseException;lineNumber:3;columnNumber:39;mapperDOCTYPEconfigurationatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)atorg.springframework.beans.factory.support.AbstractBeanFactory1.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:743)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at com.auth.spring.listener.SpringLoaderListener.contextInitialized(SpringLoaderListener.java:24)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1409)atorg.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutorWorker.run(UnknownSource)atjava.lang.Thread.run(UnknownSource)Causedby:org.springframework.core.NestedIOException:Failedtoparsemappingresource:URL[jar:file:/D:/apachetomcat8.0.22/webapps/xingheplatformweb/WEBINF/lib/xinghebase0.0.1SNAPSHOT.jar!/com/xinghe/edu/auth/model/mapper/AuthChildrenGroupMapper.xml];nestedexceptionisorg.apache.ibatis.builder.BuilderException:Errorcreatingdocumentinstance.Cause:org.xml.sax.SAXParseException;lineNumber:3;columnNumber:39;mapperDOCTYPEconfigurationatorg.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:468)atorg.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:343)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)22moreCausedby:org.apache.ibatis.builder.BuilderException:Errorcreatingdocumentinstance.Cause:org.xml.sax.SAXParseException;lineNumber:3;columnNumber:39;mapperDOCTYPEconfigurationatorg.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:259)atorg.apache.ibatis.parsing.XPathParser.(XPathParser.java:125)atorg.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:78)atorg.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:464)25moreCausedby:org.xml.sax.SAXParseException;lineNumber:3;columnNumber:39;mapperDOCTYPEconfigurationatcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(UnknownSource)atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImplContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImplFragmentContentDriver.next(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImplPrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:257)
… 28 more
十二月 15, 2015 2:07:20 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class com.auth.spring.listener.SpringLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in file [D:\apache-tomcat-8.0.22\webapps\xinghe-platform-web\WEB-INF\classes\spring\applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘URL [jar:file:/D:/apache-tomcat-8.0.22/webapps/xinghe-platform-web/WEB-INF/lib/xinghe-base-0.0.1-SNAPSHOT.jar!/com/xinghe/edu/auth/model/mapper/AuthChildrenGroupMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
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.AbstractBeanFactory1.getObject(AbstractBeanFactory.java:303)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:743)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)atcom.auth.spring.listener.SpringLoaderListener.contextInitialized(SpringLoaderListener.java:24)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)atorg.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBaseStartChild.call(ContainerBase.java:1399)atjava.util.concurrent.FutureTask.run(UnknownSource)atjava.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)atjava.util.concurrent.ThreadPoolExecutorWorker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘URL [jar:file:/D:/apache-tomcat-8.0.22/webapps/xinghe-platform-web/WEB-INF/lib/xinghe-base-0.0.1-SNAPSHOT.jar!/com/xinghe/edu/auth/model/mapper/AuthChildrenGroupMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:468)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:343)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
… 22 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:259)
at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:125)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:78)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:464)
… 25 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 39; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImplContentDriver.scanRootElementHook(UnknownSource)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImplFragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:257)
… 28 more

发生此错误的原因:


mybatis的映射文件 *Mapper.xml文件头错误,我是直接从sql-map-config.xml文件中复制过来的,如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

很明显,DOCTYPE 是 configuration ,而这个文件中的根节点是 mapper,互相不匹配,所以产生了这个错误;

解决办法


修改为以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

总结


在写一些代码或配置的时候,经常可能从别的地方复制一个过来改改,这样是比较方便快捷,但如果忘记了改某个位置,就可能产生一些奇奇怪怪的错误!

上一篇:《大数据原理:复杂信息的准备、共享和分析》一一2.6 单向哈希函数


下一篇:currentFrameLabel和currentLabel的区别在于flash player9和10