面对org.xml.sax.SAXParseException

时间:2015-03-30 18:06:14

标签: java xml web-services hibernate rest

以下是 web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.javacodegeeks.enterprise.rest.jersey</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Assume students is the database name -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
root
</property>
</session-factory>
</hibernate-configuration>

这是我面临的错误:

  

严重:在第21行第2列解析致命错误:标记中的标记   根元素后面的文档必须格式正确。   org.xml.sax.SAXParseException;的systenId:   JNDI:/localhost/JAXRS-HelloWorld/WEB-INF/web.xml; lineNumber:21;   columnNumber:2;根元素后面的文档中的标记   必须是良好的形式。在   com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(未知   来源)at   com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ TrailingMiscDriver.next(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(未知   来源)at   com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl $ JAXPSAXParser.parse(未知   来源)at   org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)at at   org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1890)     在   org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1259)     在   org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)     在   org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)     在   org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)     在   org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5269)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549)     在java.util.concurrent.FutureTask.run(未知来源)at   java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)at   java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)at   java.lang.Thread.run(未知来源)

     

2015年3月30日下午11:27:38 org.apache.catalina.startup.ContextConfig   parseWebXml SEVERE:解压缩应用程序web.xml文件中的错误   JNDI:/localhost/JAXRS-HelloWorld/WEB-INF/web.xml   org.xml.sax.SAXParseException;的systenId:   JNDI:/localhost/JAXRS-HelloWorld/WEB-INF/web.xml; lineNumber:21;   columnNumber:2;根元素后面的文档中的标记   必须是良好的形式。在   com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(未知   来源)at   com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ TrailingMiscDriver.next(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(未知   来源)at   com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(未知   来源)at   com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(未知   来源)at   com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl $ JAXPSAXParser.parse(未知   来源)at   org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)at at   org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1890)     在   org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1259)     在   org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)     在   org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)     在   org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)     在   org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5269)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549)     在java.util.concurrent.FutureTask.run(未知来源)at   java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)at   java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)at   java.lang.Thread.run(未知来源)

2 个答案:

答案 0 :(得分:0)

您的(基本XML)解析错误来自于在您的文档中找到了两个根标记(<web-app><hibernate-configuration>)。

看起来您只是收集了两个XML配置文件的内容,但它并没有像这样工作。如评论中所述,必须在web.xml中设置webapp配置,并且通常在hibernate.cfg.xml中设置Hibernate。

答案 1 :(得分:0)

每当您遇到curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash nvm install 8.5.0 nvm use 8.5.0 //check with node -v 类型的异常时,最好先验证您的xml。 当您想通过上传或粘贴文本来验证xml文件时,This site会派上用场。