解決spring mvc No mapping found for HTTP request with URI spring mvc錯誤的三種方法

 

 

 

 

 

 

 

 

1、控制層沒有被spring掃描到,控制層沒有實例化,檢查自己的控制層是否被spring掃描到,檢查以下配置:<context:component-scan base-package=""/>

 

2、web.xml配置文件的<url-pattern>標籤配置成<url-pattern>/*</url-pattern>,正確的配置應該是<url-pattern>/</url-pattern>。學了structs之後再學spring mvc框架的          就會很容易犯這個錯誤。

 

3、使用的是註解實例化控制層,且web.xml的路徑配置爲<url-pattern>/</url-pattern>,卻沒有在spring的配置文件使用<mvc:annotation-driven />標籤,導致URL解析出錯,檢查是否加上<mvc:annotation-driven />。

 

 

當我們需要controller返回一個map的json對象時,可以設定<mvc:annotation-driven />,

同時設定<mvc:message-converters> 標籤,設定字符集和json處理類,例如:

<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章