SpringMVC配拦截器报错[dispatcherServlet]:Servlet.service() for servlet [dispatcherServlet] threw exception

这个可以说是一个很麻烦的bug了 看日志文件也看不出代码具体哪里出现异常

2020-03-18 11:41:23.585 ERROR 3644 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[.[dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] threw exceptionjava.lang.StackOverflowError: null at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582) ~[tomcat-embed-core-9.0.31.jar:9.0.31]

配置了登录的拦截器 然后项目就没成功跑起来过 把拦截器去掉就可以正常访问
上百度搜了半天也没查出个所以然来 很无奈
最后打了断点 发现代码一直在拦截器类的执行前方法里不停的做死循环递归
如下图:
SpringMVC配拦截器报错[dispatcherServlet]:Servlet.service() for servlet [dispatcherServlet] threw exception
文章图片

后来觉得可能是拦截的路径出问题了 导致请求转发的路径也被拦截了
可明明已经放行该路径了呀
仔细看了半天 发现放行路径少写了个斜杠 /
SpringMVC配拦截器报错[dispatcherServlet]:Servlet.service() for servlet [dispatcherServlet] threw exception
文章图片

就是在红线地方的斜杠 必须要加!!! 【SpringMVC配拦截器报错[dispatcherServlet]:Servlet.service() for servlet [dispatcherServlet] threw exception】SpringMVC配拦截器报错[dispatcherServlet]:Servlet.service() for servlet [dispatcherServlet] threw exception
文章图片

SpringMVC配拦截器报错[dispatcherServlet]:Servlet.service() for servlet [dispatcherServlet] threw exception
文章图片

完美解决

    推荐阅读