解决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>

原创文章 4 获赞 3 访问量 643

猜你喜欢

转载自blog.csdn.net/qq_42907074/article/details/106038181