java - 添加mvc后Spring MVC页面无法访问:resources

标签 java spring spring-mvc resources

结构:

Structure

mvc-dispatcher-servlet.xml:

<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: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/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.javaguru.game"/>

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

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

Controller :

@Controller
public class MainController {
    @RequestMapping(value = {"/", "/home"}, method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Hello world!");
        return "hello";
    }
}

添加 mvc:resource 标签后,我可以访问我的 Assets (这里一切都很好,因为它应该是这样): Everything is fine

但是之后,如果我尝试访问我的主页,它就不再工作了: Homepage is not working

问题可能出在哪里?

提前致谢。

最佳答案

我认为你使用的是spring 3。你需要添加

<mvc:annotation-driven> 

运行

<mvc:resources>

你能试试这个吗?

关于java - 添加mvc后Spring MVC页面无法访问:resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33529632/

相关文章:

java - 忘记关闭 ServerSocket

java - 损坏的 pdf 已解码并通过 Java 服务器套接字发送

java - 从 Alfresco 集成测试上下文访问 Spring bean

java - 为什么 UriComponentsBuilder 忽略空查询参数?

java - 如何从Windows连接远程Q管理器(在docker上)?

java - spring ldap 测试 - 自定义架构?

html - 自定义范围输入

java - 无法在上下文加载之前在 spring 中发布自定义事件

spring 3 定时任务运行3次

spring - Spring Cloud AWS如何从缓存集群的逻辑名称获取配置端点?