欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException

程序员文章站 2022-07-02 15:47:32
NoSuchRequestHandlingMethodException ......

相信很多的朋友在开发过程中都或多或少的遇见一些异常,下面我给大家说一说nosuchrequesthandlingmethodexception

这个异常说的是找不到处理这样的请求方法,那是什么原因导致的:

下面我来说说我的在项目中遇见的,上线的项目运行了两周,查看日志记录,就出现了一个异常信息:

[error] [2018-10-18 01:41:28] com.shou6.utils.exception.exceptionhandler.resolveexception(54) | spring异常捕获顶层
org.springframework.web.servlet.mvc.multiaction.nosuchrequesthandlingmethodexception: no matching handler method found for servlet request: path '/server.do', method 'get', parameters map[[empty]]
	at org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter$servlethandlermethodresolver.resolvehandlermethod(annotationmethodhandleradapter.java:679)
	at org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.invokehandlermethod(annotationmethodhandleradapter.java:441)
	at org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.handle(annotationmethodhandleradapter.java:434)
	at org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:943)
	at org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:877)
	at org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966)
	at org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:857)
	at javax.servlet.http.httpservlet.service(httpservlet.java:622)
	at org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842)
	at javax.servlet.http.httpservlet.service(httpservlet.java:729)
	at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:292)
	at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207)
	at org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52)
	at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240)
	at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207)
	at com.shou6.filter.requestattributefilter.dofilter(requestattributefilter.java:28)
	at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240)
	at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207)
	at org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88)
	at org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107)
	at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:240)
	at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:207)
	at org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:212)
	at org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:94)
	at org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:504)
	at org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:141)
	at org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79)
	at org.apache.catalina.valves.remoteipvalve.invoke(remoteipvalve.java:676)
	at org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:620)
	at org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88)
	at org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:502)
	at org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1132)
	at org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:684)
	at org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1533)
	at org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1489)
	at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)
	at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)
	at org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61)
	at java.lang.thread.run(thread.java:745)

  

经过排查发现请求的url-server.do后面没有跟参数导致的,于是做了如下操作:

在filter中加判断

if ("".equals(request.getparameter("method")) || request.getparameter("method") == null) {
            //            return json4map(jsonmap, null, "请求参数错误 ", statuscode_failed_server);
            response.getwriter().write("request parameter error");
            return;
        }

  

这样就不会报错了。

如有需要可以加我q群【308742428】大家一起讨论技术。

后面会不定时为大家更新文章,敬请期待。

喜欢的朋友可以关注下。