2017-09-03 340 views
0

我得到一個org.xml.sax.SAXParseException啓動我的Spring MVC應用程序。我一直在瘋狂谷歌搜尋,試圖找出這一個。這是我在Tomcat 8.0.30中獲得的。獲取org.xml.sax.SAXParseException啓動Spring MVC應用程序

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 72; Document root element "beans", must match DOCTYPE root "xml". 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) 
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) 
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) 
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) 
     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) 
     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) 
     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) 
     at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:612) 

plus a whole bunch more lines 

這是我的applicationContext.xml。第11行以spring-mvc-4.3.xsd結尾。

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE xml> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-4.3.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> 
    <mvc:annotation-driven /> 

    <mvc:resources location="WEB-INF/pages/images/" mapping="/images/**" /> 

    <mvc:view-controller path="/" view-name="home" /> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/pages/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql://10.128.219.28:3306/ghscom_ghs86" /> 
     <property name="username" value="ghscom_root" /> 
     <property name="password" value="GHSMatadors1986" /> 
    </bean> 
</beans> 

這是我對maven的pom.xml。我應該指出,我是Maven的新手,所以如果問題出在這裏,那就是原因。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>ghs1986</groupId> 
    <artifactId>ghs1986</artifactId> 
    <version>home</version> 
    <packaging>war</packaging> 
    <build> 
     <sourceDirectory>src</sourceDirectory> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.5.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <warSourceDirectory>WebContent</warSourceDirectory> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>4.3.0.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>3.5.6-Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context-support</artifactId> 
      <version>3.2.0.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>4.3.0.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>4.3.0.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-dao</artifactId> 
      <version>2.0.8</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-jdbc</artifactId> 
      <version>4.3.0.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>jstl</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 
    </dependencies> 
</project> 

回答

0
<!DOCTYPE xml> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    .... 

隨着<!DOCTYPE xml>你告訴根元素將是<xml>,不<beans> XML解析器。

完全刪除DOCTYPE聲明,即舊式DTD驗證,並使用模式。

如果你仍在使用DTD驗證(我認爲這是不推薦使用)的DOCTYPE會像

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" 
    "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> 

但是這將是Spring 2.0中,這是古老的。

相關問題