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

时间:2015-11-04 18:43:52

标签: 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
public class MainController {
    @RequestMapping(value = {"/", "/home"}, method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Hello world!");
        return "hello";
    }
}

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

但在那之后,如果我试图访问我的主页,它就不再起作用了: Homepage is not working

哪里可能是问题?

提前致谢。

1 个答案:

答案 0 :(得分:1)

我认为你正在使用spring 3.你需要添加

<mvc:annotation-driven> 

运行

<mvc:resources>

你可以尝试一下吗?