Spring Boot项目运行报错:Servlet.service() for servlet [dispatcherServlet] threw exception

问题描述:
spring boot项目启动之后,访问时报错。

控制台的错误输出:

2020-06-29 12:25:44.780 ERROR 1968 --- [nio-8080-exec-4] 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.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	

原因分析:
在Service层的实现类中,没有添加@Autowired注解,这会导致实现类缺少依赖,在项目启动之后,找不到注解的依赖,就会产生错误。

原始代码:

   private EmployeeDao employeeDao;

添加注解后修改的代码:

 @Autowired
   private EmployeeDao employeeDao;

通过添加@Autowired注解后,问题得到解决。

你可能感兴趣的:(Spring,Boot,spring,boot,java)