Ibatis解析配置文件报错"Premature end of file."

http://bbs.csdn.net/topics/350207287/【这篇博客很厉害,不过我的代码异常,不是因为中文注释引起的】

 

引起原因,我的猜测是:在sqlMapConfig.xml中,添加了如下的XML文件引用,却只有一个里面有内容

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
	<properties resource="SqlMap.properties"/>
	
	<transactionManager type="JDBC">
		<dataSource type="SIMPLE">
			<property name="JDBC.Driver" value="${driver}"/>
			<property name="JDBC.ConnectionURL" value="${url}"/>
			<property name="JDBC.Username" value="${username}"/>
			<property name="JDBC.Password" value="${password}"/>
		</dataSource>
	</transactionManager>
	<!-- 只有第一个UserInfo.xml有内容,其他两个XML都是空白文档 -->
	<sqlMap resource="com/alex/mealorder/vo/UserInfo.xml"/>
	<sqlMap resource="com/alex/mealorder/vo/MealInfo.xml"/>
	<sqlMap resource="com/alex/mealorder/vo/OrderHistory.xml"/>
</sqlMapConfig>

 

修改完毕就可以了。如下是报错的系统日志。

 

Exception in thread "main" java.lang.RuntimeException: Error occurred.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Premature end of file.
	at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:89)
	at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
	at com.alex.mealorder.dao.CommonsDAO.getClient(CommonsDAO.java:27)
	at com.alex.mealorder.dao.UserInfoDAO.getAllUsers(UserInfoDAO.java:19)
	at com.alex.mealorder.dao.test.TestUserInfoDAO.main(TestUserInfoDAO.java:11)
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Premature end of file.
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
	at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:86)
	... 4 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Premature end of file.
	at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
	... 5 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Premature end of file.
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
	at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse(SqlMapParser.java:51)
	at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$11.process(SqlMapConfigParser.java:410)
	at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
	... 9 more
Caused by: org.xml.sax.SAXParseException: Premature end of file.
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(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.XMLVersionDetector.determineDocVersion(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 com.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:157)
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:50)
	... 12 more

 

 

你可能感兴趣的:(ibatis)