完整異常
org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:201) org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:420) org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:366) org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:66) org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:404) org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1233) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1016) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) com.github.xiaoymin.swaggerbootstrapui.filter.SecurityBasicAuthFilter.doFilter(SecurityBasicAuthFilter.java:84) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) com.github.xiaoymin.swaggerbootstrapui.filter.ProductionSecurityFilter.doFilter(ProductionSecurityFilter.java:53) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
首先看異常信息,,,直接看第一行,,,大概說的是【請求映射信息處理器映射】中的【handle沒有匹配】錯誤,,,
接着直接定位到錯誤類的錯誤方法,就是下面這個 👇👇👇,,,
1 protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> infos, String lookupPath, HttpServletRequest request) throws ServletException { 2 RequestMappingInfoHandlerMapping.PartialMatchHelper helper = new RequestMappingInfoHandlerMapping.PartialMatchHelper(infos, request); 3 if (helper.isEmpty()) { 4 return null; 5 } else { 6 Set mediaTypes; 7 if (helper.hasMethodsMismatch()) { 8 mediaTypes = helper.getAllowedMethods(); 9 if (HttpMethod.OPTIONS.matches(request.getMethod())) { 10 RequestMappingInfoHandlerMapping.HttpOptionsHandler handler = new RequestMappingInfoHandlerMapping.HttpOptionsHandler(mediaTypes); 11 return new HandlerMethod(handler, HTTP_OPTIONS_HANDLE_METHOD); 12 } else { 13 throw new HttpRequestMethodNotSupportedException(request.getMethod(), mediaTypes); 14 } 15 } else if (helper.hasConsumesMismatch()) { 16 mediaTypes = helper.getConsumableMediaTypes(); 17 MediaType contentType = null; 18 if (StringUtils.hasLength(request.getContentType())) { 19 try { 20 contentType = MediaType.parseMediaType(request.getContentType()); 21 } catch (InvalidMediaTypeException var8) { 22 throw new HttpMediaTypeNotSupportedException(var8.getMessage()); 23 } 24 } 25 26 throw new HttpMediaTypeNotSupportedException(contentType, new ArrayList(mediaTypes)); 27 } else if (helper.hasProducesMismatch()) { 28 mediaTypes = helper.getProducibleMediaTypes(); 29 throw new HttpMediaTypeNotAcceptableException(new ArrayList(mediaTypes)); 30 } else if (helper.hasParamsMismatch()) { 31 List<String[]> conditions = helper.getParamConditions(); 32 throw new UnsatisfiedServletRequestParameterException(conditions, request.getParameterMap()); 33 } else { 34 return null; 35 } 36 } 37 }
接着跟着調試,會發現問題是第9行代碼出現了問題,13行拋出的該異常,也就是
if (HttpMethod.OPTIONS.matches(request.getMethod())) { RequestMappingInfoHandlerMapping.HttpOptionsHandler handler = new RequestMappingInfoHandlerMapping.HttpOptionsHandler(mediaTypes); return new HandlerMethod(handler,HTTP_OPTIONS_HANDLE_METHOD); } else { throw new HttpRequestMethodNotSupportedException(request.getMethod(), mediaTypes);
}
結論:
調試就會發現是 【OPTIONS】匹配不上【POST】方法,這樣就讓我不由得看了看自己方法的方法請求方式,,,
一看真是【GET】,改的和前端一樣就好了...
所以前后端分離項目中,,,猴子們的溝通真的很重要啊,,,
像我就是不知道前端什么時候"偷偷"改成了post = =