java - Spring 3.1.1 SAXParseException 与 mvc :resources

标签 java spring spring-mvc rad websphere-7

我的日志中出现以下错误:

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources'.

当我尝试在浏览器中查看我的应用程序时,会出现此情况:

Error 500: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet

这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    id="WebApp_ID"
    version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>MyAwesomeApp</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

这是我的 spring-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/mvc/spring-mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan
        base-package="org.myapp.controllers" />
    <bean
        id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property
            name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property
            name="prefix"
            value="/WEB-INF/views/" />
        <property
            name="suffix"
            value=".jsp" />
    </bean>
    <mvc:resources
        mapping="/resources/**"
        location="/resources/" />
</beans>

我做错了什么?如果我取出<mvc:resources标记,我的应用程序显示了,但其 CSS 未加载。

编辑:也许我还有其他一些问题,因为现在我没有收到该错误,尽管我的应用程序没有显示 - 我只是得到了 404。我确实得到了现在日志中的内容看起来很有希望:

SimpleUrlHand I org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'

最佳答案

您在 spring-servlet.xml 中的 namespace 声明中犯了错误。 请更改:

xsi:schemaLocation="
(...)
http://www.springframework.org/schema/mvc/spring-mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
(...)"

至:

xsi:schemaLocation="
(...)
http://www.springframework.org/schema/mvc/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
(...)"

自从您声明以来

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

不是(...)/schema/spring-mvc

关于java - Spring 3.1.1 SAXParseException 与 mvc :resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9896885/

相关文章:

java - 不是自动创建 Hibernate 模式,而是使用 SQL 脚本

java - 使用 spring @RestController 在 null 上返回 HTTP 204

spring - PreparedStatementCallback;SQL[SQLStatememnt] 的无效结果集访问;嵌套异常是 java.sql.SQLException :Invalid column index Spring Auth

java - 如何使用 spring boot 和 jpa 一起软删除父级和子级(级联)

java - Vert.x 启动应用程序和配置文件的方式

java - JAXB 忽略 XmlElement 指令

java - 使用装箱类型数组(例如整数)创建张量与 tensorflow 中的基元数组创建张量是否存在差异

spring - 在构建微服务时如何获取与 Spring OAuth 中的访问 token 关联的范围?

Spring 启动 : configure it to find the webapp folder

java - 不同模块的注释 spring 上下文的问题