java - 实现资源映射后,Spring MVC 映射不起作用

标签 java spring spring-mvc

在我的上下文文件中,我想添加行以便能够访问静态内容。在我添加它之前,一切正常,但在添加它之后,我无法访问具有某些 Controller 的页面,并且收到此警告:WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/fit/] in DispatcherServlet with name 'mvc-dispatcher' 。添加之前 <mvc:resources mapping="/resources/**" location="/resources/" />到上下文文件,它看起来像这样:

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

<context:annotation-config />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
    up static resources in the ${webappRoot}/resources directory -->




<context:component-scan base-package="cz.cvut.fit.genepi.controllers" />
<import resource="classpath:applicationContext-security.xml" />
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<mvc:resources mapping="/resources/**" location="/resources/" />
    </beans>

知道如何解决这个问题吗?

PS:这些页面受到 Spring 安全性的保护,但我不认为这可能是问题所在。

最佳答案

每个调度程序 servlet 都以 -servlet 结尾。 尝试重命名您的调度程序 servlet。

在初始化 DispatcherServlet 时,框架将在 Web 应用程序的 WEB-INF 目录中查找名为 [servlet-name]-servlet.xml 的文件,并创建其中定义的 bean。

关于java - 实现资源映射后,Spring MVC 映射不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15536453/

相关文章:

java - Spring Boot 3.0/Security 6.0 迁移 - SecurityFilterChain 中的 "EL1057E: No bean resolver registered in the context to resolve access to bean..."

java - 这段代码中的LinkedHashSet可以换成HashSet吗?

java - 如何在arangodb中使用Tinkerpop蓝图API获取所有顶点和边

java - 从 Java 代码设置 JRE 变量

spring - 如何在 Spring Boot 中处理 HTTP OPTIONS 请求?

java - Spring MVC : How to pass model object to controller method with out using form

java.lang.NoClassDefFoundError : net/sf/cglib/asm/util/TraceClassVisitor

java - Spring应用中Eureka健康检查的问题

java - Spring 添加默认值以形成 :options in jsp

java - 使用 spring mvc 在 junit 测试中删除方法