【问题标题】:Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd无法读取架构文档'http://www.springframework.org/schema/beans/spring-beans.xsd
【发布时间】:2015-11-01 12:15:53
【问题描述】:

我正在尝试使用 maven 设置示例 spring-mvc helloworld 程序。我确实在论坛中搜索了所有可用的答案,但无法得到答案。 以下是 dispatcher-servlet.xml 中出现的错误

  • schema_reference.4: 无法读取架构文档 'http://www.springframework.org/schema/beans/ spring-beans.xsd',因为 1) 找不到文件; 2) 文件无法读取; 3) 的根元素 文件不是。
  • cvc-elt.1:找不到元素“beans”的声明。

下面是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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.crm</groupId>
  <artifactId>coll</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>coll Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
        <spring.version>4.0.1.RELEASE</spring.version>
        <javax.servlet.version>2.3</javax.servlet.version>
        <spring.batch.version>2.2.0.RELEASE</spring.batch.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!-- Spring dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>${javax.servlet.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.8</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-io</artifactId>
                <version>1.3.2</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.batch</groupId>
                <artifactId>spring-batch-core</artifactId>
                <version>${spring.batch.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.batch</groupId>
                <artifactId>spring-batch-infrastructure</artifactId>
                <version>${spring.batch.version}</version>
            </dependency>
            <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
  <build>
    <finalName>coll</finalName>
    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
  </build>
</project>

下面是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" id="WebApp_ID" version="3.0">

  <display-name>Archetype Created Web Application</display-name>
  <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
</web-app>

下面是dispatcher-servlet.xml

<?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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.crm.bill.controller" />

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

谁能帮我知道 dispatcher-servelt.xml 出了什么问题。任何帮助表示赞赏

【问题讨论】:

    标签: java xml spring spring-mvc xsd


    【解决方案1】:

    在您的调度程序 servlet 上,bean 定义不存在。因此,在您的 bean 声明中添加以下内容--

    xmlns:beans="http://www.springframework.org/schema/beans"
    

    另外,您需要在schemalocation 中提供bean xsd 版本,如下所示,

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

    (我给了spring-beans-3.2.xsd版本,你可以根据你的要求提到任何可用的版本)

    在这次更新之后,大部分情况下您都可以运行您的代码,但如果仍然遇到任何错误,请尝试使用&lt;beans:bean.. 声明所有 bean。

    【讨论】:

      【解决方案2】:

      尝试使用特定的xsd。在 dispatcher-servlet.xml 中更改 xsd 声明如下 -:

      http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

      【讨论】:

      • 我也试过了。它给出了同样的错误。更新 maven 项目后。 schema_reference.4:未能读取架构文档'springframework.org/schema/beansspring-beans.xsd',因为1)找不到文档; 2) 文件无法读取; 3) 文档的根元素不是 . cvc-elt.1:找不到元素“bean”的声明
      • 为什么它仍然为 schema/beans/spring-beans.xsd' 而不是 schema/beans spring-beans-4.0.xsd' 提供错误!!?你试过干净的构建吗?
      • 刚接触 maven 和 spring。如何进行干净的构建?我还没有在服务器中启动它
      猜你喜欢
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      • 2015-05-17
      • 2012-09-01
      • 2014-12-04
      • 2015-06-10
      • 1970-01-01
      相关资源
      最近更新 更多