springboot报错java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping

报错的位置:

执行完程序即将返回静态页面的时候

springboot报错java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping_第1张图片

报错控制台: 

springboot报错java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping_第2张图片

在打印出数据后,返回静态页面时,报出如下的错:

2019-12-07 16:52:23.115 ERROR 104 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost]           : Exception Processing ErrorPage[errorCode=0, location=/error]

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
	at org.apache.catalina.core.ApplicationHttpRequest.setRequest(ApplicationHttpRequest.java:708) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationHttpRequest.(ApplicationHttpRequest.java:114) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationDispatcher.wrapRequest(ApplicationDispatcher.java:917) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:358) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:394) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:253) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:348) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:173) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_191]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_191]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]

在长时间的百度后,发现了网上说的解决方法无非就是:

  • tomcat版本不匹配,更换tomcat版本。我用的内置tomcat,这个不考虑,用本地的可以考虑换个高版本的。
  • 用jdk下的jar替换tomcat\lib下面的
  • 用RestController注解替换Controller注解,这个倒是没报错,但是返回了一个字符串,return里的内容
    • RestController相当于Controller注解和ResponseBody注解加到一块,而ResponseBody注解的作用是返回json或者数据给前台。

上面的最后都没解决根本问题,

下面说我的实验结果

最后将springboot版本从最新版的2.2.2改成2.0.5版本的,程序可以正常运行,毫无违和感

springboot报错java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping_第3张图片

总结:不知道是最新版本的springboot有bug还是我环境有问题,反正就是好使了,希望能帮到和我一样问题的人,同样问题的可以交流一波,真的想知道为什么报错。

 

你可能感兴趣的:(杂项)