Spring MVC 3中关于urlpattern设成"/"后,资源访问问题

SpringMVC3中关于url-pattern设成"/"后,CSS等资源的访问会报错:No mapping found for HTTP request with URI。

解决办法是将资源类文件夹放到resources目录中,然后在 servlet-context.xml中 添加

xmlns:mvc="http://www.springframework.org/schema/mvc"
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

运行服务输出:

INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
 


原文地址:https://www.cnblogs.com/mobile/p/2265795.html