结构:
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 (这里一切都很好,因为它应该是这样):
问题可能出在哪里?
提前致谢。
最佳答案
我认为你使用的是spring 3。你需要添加
<mvc:annotation-driven>
运行
<mvc:resources>
你能试试这个吗?
关于java - 添加mvc后Spring MVC页面无法访问:resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33529632/