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

  • Post author:
  • Post category:其他


这个可以说是一个很麻烦的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]

配置了登录的拦截器 然后项目就没成功跑起来过 把拦截器去掉就可以正常访问

上百度搜了半天也没查出个所以然来 很无奈

最后打了断点 发现代码一直在拦截器类的执行前方法里不停的做死循环递归

如下图:

在这里插入图片描述

后来觉得可能是拦截的路径出问题了 导致请求转发的路径也被拦截了

可明明已经放行该路径了呀

仔细看了半天 发现放行路径

少写了个斜杠 /


在这里插入图片描述



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

在这里插入图片描述

在这里插入图片描述



完美解决



版权声明:本文为Piconjo原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。