标签:spring mvc no mapping found for http request with uri
问题原因:罪魁祸首是web.xml下对spring的DispatcherServlet请求url映射的配置,原配置如下:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
分析原因:<servlet-mapping>的<url-pattern>/</url-pattern>把所有的请求都交给spring去处理了,而所有available的请求url都是在Constroller里使用类似@RequestMapping(value = "/login/{user}", method = RequestMethod.GET)这样的注解配置的,这样的话对js/css/jpg/gif等静态资源的访问就会得不到。
解决方法:在web.xml里添加如下的配置
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
解决方法2:在spring的配置文件中添加如下一行:
<mvc:default-servlet-handler/>
注意,需要是spring3.0.5以上版本
解决方法3
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
这个配置告诉spring 静态资源的处理方式
本文出自 “JodyRex” 博客,请务必保留此出处http://503431920.blog.51cto.com/6681280/1642256
spring mvc No mapping found for HTTP request with URI
标签:spring mvc no mapping found for http request with uri
原文地址:http://503431920.blog.51cto.com/6681280/1642256