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 exception

java.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_第1张图片

后来觉得可能是拦截的路径出问题了 导致请求转发的路径也被拦截了
可明明已经放行该路径了呀

仔细看了半天 发现放行路径少写了个斜杠 /
在这里插入图片描述

就是在红线地方的斜杠 必须要加!!!

在这里插入图片描述
在这里插入图片描述

完美解决

你可能感兴趣的:(异常解决)