报错: No mapping found for HTTP request with URI [/xxx/xxx] in DispatcherServlet with name 'xxx'

版权声明:本文为Niz原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39403734/article/details/79093906

报错:

No mapping found for HTTP request with URI [/xxx/xxx] in DispatcherServlet with name 'xxx'

 

再晚上看了挺多的资料,最终还是没能解决这个问题;

主要是因为这个报错的原因有很多种,下面我就来说一下我总结报错的几个可能点:

1. Controller的注解没写

2. Springmvc.xml里面的扫描包路径不对

3. Springmvc.xml里面的没有些注解驱动

4. 访问路没被Web.xml里面的Servlet映射到

 

解决方案:

1. Controller的注解没写

(1) 直接去Controller@Controller或者@RestController加在类名称上方就好;

2. SoringMVC.XML里的扫描包不对

(1) 检查一下<context:component-scan base-package="com.xxx.xxx" />的路径是否对应得上,最好是直接复制包路径省心;

3. Springmvc.xml里面的没有些注解驱动

(1) 如果扫描包没问题那你看看你的注解驱动是否加上了,就下面这东西

<mvc:annotation-driven/>

4. 访问路没被Web.xml里面的Servlet映射到

(1) 如果<url-pattern>/</url-pattern>的话一般都能映射到的

(2) 如果<url-pattern>*.html</url-pattern>的话,你后缀没加上.html就是映射不到的,就会出现上面的报错

 

以上是本人小结的解决方案;

猜你喜欢

转载自blog.csdn.net/qq_39403734/article/details/79093906