2017-06-14 45 views
0

我想寫一些簡單的控制器。現在我有一個我無法理解的問題。請幫幫我。HTTP狀態500 - 無法找到元素'豆'的聲明

的pom.xml:

<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>Diplom</groupId> 
<artifactId>Diplom</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 
<properties> 
    <java-version>1.6</java-version> 
    <org.springframework-version>4.1.5.RELEASE</org.springframework-version> 
    <org.aspectj-version>1.7.4</org.aspectj-version> 
    <org.slf4j-version>1.7.5</org.slf4j-version> 
    <hibernate.version>4.3.5.Final</hibernate.version> 
    <mysql.version>5.1.29</mysql.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>4.1.8.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>4.1.8.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.36</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>${hibernate.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
     <version>${hibernate.version}</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.5.1</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1.1</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<name>Diplom</name> 
<description>Firth big project! :)</description> 

的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<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" 
version="3.0"> 
<servlet> 
    <servlet-name>myServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/myServlet-servlet.xml</param-value> 
    </init-param> 
</servlet> 
<servlet-mapping> 
    <servlet-name>myServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
</web-app>` 

myServlet-servlet.xml中:

<beans xmlns="http:/www.springframework.org/schema/beans" 
xmlns:ctx="http://www.springframework.org/schema/context" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans.xsd  
http://www.springframework.org/schema/mvc  
http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/context  
http://www.springframework.org/schema/context/spring-context.xsd "> 
    <ctx:annotation-config> 
    </ctx:annotation-config> 
    <ctx:component-scan base-package="controllers"> 
    </ctx:component-scan> 
</beans> 

Exeption的文字:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 
7 in XML document from ServletContext resource [/WEB-INF/myServlet- 
servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; 
lineNumber: 7; columnNumber: 59; cvc-elt.1: Cannot find the declaration of 
element 'beans'. 

我試圖刪除「7系」但後來我對「6號線」異常= d 請幫助我瞭解什麼是錯的

+0

提供您完整的包名嘿,看來這是因爲缺少'/'HTTP後'的:'在第一行'<豆的xmlns =「HTTP:/www.springframework.org /模式/豆「'。您是否嘗試添加架構的正確URL? –

+0

哦... 謝謝你!你是我的英雄! = D – BruceVVayne

+0

此外,您可能不需要那裏的結束標記,請參閱下面的答案。 –

回答

0

您可能需要將spring-beans依賴添加到您的Maven 。

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-beans</artifactId> 
    <version>4.1.8.RELEASE</version> 
</dependency> 
+0

沒有幫助 並沒有嘗試添加「指定版本」(和此組合) – BruceVVayne

0

你需要指定春天的版本使用的是在你的servlet配置 - 你的情況彈簧豆-4.1.xsd

xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 
... 
+0

沒有幫助 並沒有嘗試添加「依賴於maven」(和這個組合) – BruceVVayne

0

可以請你下面的嘗試servlet xml?在此我刪除了結束標記,而不是將它們用作<context:annotation-config /><context:component-scan />。也請在component-scan

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 

    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd"> 
    <context:annotation-config /> 
    <context:component-scan base-package="controllers" /> 
</beans> 
相關問題