问题描述
错误信息:java.lang.ExceptionInInitializerErrorCausedby:java.lang.RuntimeException:Erroroccurred.Cause:com.ibatis.common.xml.NodeletException:ErrorparsingXML.Cause:org.xml.sax.SAXParseException:XMLdocumentstructuresmuststartandendwithinthesameentity.atcom.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:89)atcom.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)atcom.ibatis.blackcoat.dao.impl.BlackcoatDaoImpl.<clinit>(BlackcoatDaoImpl.java:19)Causedby:com.ibatis.common.xml.NodeletException:ErrorparsingXML.Cause:org.xml.sax.SAXParseException:XMLdocumentstructuresmuststartandendwithinthesameentity.atcom.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)atcom.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:86)...2moreCausedby:org.xml.sax.SAXParseException:XMLdocumentstructuresmuststartandendwithinthesameentity.atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)atcom.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1411)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.endEntity(XMLDocumentFragmentScannerImpl.java:902)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.endEntity(XMLDocumentScannerImpl.java:605)atcom.sun.org.apache.xerces.internal.impl.XMLEntityManager.endEntity(XMLEntityManager.java:1393)atcom.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1763)atcom.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1242)atcom.sun.org.apache.xerces.internal.impl.XMLScanner.scanComment(XMLScanner.java:756)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanComment(XMLDocumentFragmentScannerImpl.java:1036)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2945)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)atcom.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)atcom.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)atcom.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)atcom.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)atcom.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)atcom.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:157)atcom.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:50)...3moreExceptioninthread"main"BlackcoatDaoImpl:packagecom.ibatis.blackcoat.dao.impl;importjava.io.IOException;importjava.io.Reader;importjava.sql.SQLException;importjava.util.List;importcom.ibatis.blackcoat.dao.IBlackcoatDao;importcom.ibatis.sqlmap.client.SqlMapClient;importcom.ibatis.sqlmap.client.SqlMapClientBuilder;importcom.ibatis.blackcoat.entity.*;importcom.ibatis.common.resources.Resources;publicclassBlackcoatDaoImplimplementsIBlackcoatDao{privatestaticSqlMapClientsqlMapClient=null;static{try{Readerreader=Resources.getResourceAsReader("com/ibatis/SqlMapConfig.xml");sqlMapClient=SqlMapClientBuilder.buildSqlMapClient(reader);reader.close();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}publicList<blackcoat>findAll(){List<blackcoat>list=null;try{list=sqlMapClient.queryForList("selectAll");}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnlist;}publicstaticvoidmain(String[]args){IBlackcoatDaodaoImpl=newBlackcoatDaoImpl();for(blackcoatblack:daoImpl.findAll()){System.out.println(black.getName());}}}SqlMapConfig.xml:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEsqlMapConfigPUBLIC"-//iBATIS.com//DTDSQLMapConfig2.0//EN""http://www.ibatis.com/dtd/sql-map-config-2.dtd"><sqlMapConfig><propertiesresource="com/ibatis/SqlMap.properties"/><transactionManagertype="JDBC"><dataSourcetype="SIMPLE"><!--JDBC驱动--><propertyvalue="${driver}"name="JDBC.Driver"/><!--数据库URL--><propertyvalue="${url}"name="JDBC.ConnectionURL"/><!--数据库用户名--><propertyvalue="${username}"name="JDBC.username"/><!--数据库密码--><propertyvalue="${password}"name="JDBC.password"/></dataSource></transactionManager><sqlMapresource="com/ibatis/blackcoat/entity/blackcoat.xml"/></sqlMapConfig>blackcoat.xml:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEsqlMapPUBLIC"-//iBATIS.com//DTDSQLMap2.0//EN""http://www.ibatis.com/dtd/sql-map-2.dtd"><sqlMap><selectid="selectAll"resultClass="com.ibatis.blackcoat.entity.blackcoat">select*fromblackcoat</select></sqlMap>第一次写iBATIS.xml也没写错啊`都是照着写的,真不知道错哪里了
解决方案
解决方案二:
根据提示的错误,问题在xml里面,应该是个某个标签的开始和结束不一致了
解决方案三:
你的配置文件有标签没结束
解决方案四:
大哥,你可以自家看看,我哪个标签没结束,我都检查了N回了
解决方案五:
XMLdocumentstructuresmuststartandendwithinthesameentity.xml文档结构必须开始结束使用同一标签.你的XML元素一定有一个,名称是错误的,这可能是因为你编码方式导致你的标签内加入了系统当前编码环境下不识别的编码字符.
解决方案六:
问题和楼主一样啊..郁闷
解决方案七:
xml里的中文注释,先加空格再接“-->”
解决方案八:
LZ看看com.ibatis.blackcoat.entity.blackcoat的类中属性是否与表blackcoat的字段一一对应呢
解决方案九:
楼主的问题解决没有,我也遇到同样的问题,束手无策,求帮忙
解决方案十:
我解决了经过仔细检查除了标签要写对应之外,就是之前楼上提到的那个中文注释问题,一定要前后空格隔开<!--说明-->