spring boot 的找不到 httpServletMapping方法的bug

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

前言

跟风使用spring boot真的挺多问题的,例如这个:
在这里插入图片描述

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
	at org.apache.catalina.core.ApplicationHttpRequest.setRequest(ApplicationHttpRequest.java:690) ~[tomcat-embed-core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.ApplicationHttpRequest.<init>(ApplicationHttpRequest.java:114) ~[tomcat-embed-core-9.0.13.jar:9.0.13]
	at org.apache.catalina.core.ApplicationDispatcher.wrapRequest(ApplicationDispatcher.java:917) ~[tomcat-embed-core-9.0.13.jar:9.0.13]

解决

请查看stackoverflow的解释,很详细了:
Spring boot: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;

鉴于国内坚固的墙壁,这里截图给大家看看:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

好了,原意思是,spring boot 用的是servlet v4,而spring boot web 用的是 spring boot web servlet v
3.1,所以有问题了。

解决方案

首先,说说有两种解决方案。

spring boot版本改为2.0

spring boot每个版本内置的tomcat版本都不一样,经过实验,2.0的版本内置的to
譬如:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.8.RELEASE)

这个版本,2.0.4和2.0.8就没有问题了,
在这里插入图片描述

解决方案2

请原谅我,暂时找不到解决方案2,因为,试过都不行。。

猜你喜欢

转载自blog.csdn.net/cdnight/article/details/87795409
今日推荐