记录问题:在springboot中servletlet调用service方法空指针异常问题

1.异常:

[2018-03-11 16:16:59.929] - 5940 严重 [http-nio-8666-exec-1] --- org.apache.catalina.core.ContainerBase.[Tomcat-1].[localhost].[/].[fileUpload]: Servlet.service() for servlet [fileUpload] in context with path [] threw exception
java.lang.NullPointerException
at com.vivo.stp.system.servlet.FileUpload.doPost(FileUpload.java:117)
//这行提示的是调用service方法那行,可是service我已经用注解注入过,还是报这个异常
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

2.解决:看了这篇博客才得以解决,在servlet方法重写的init()方法加上如下一句代码

	public void init(ServletConfig config) throws ServletException {
		// Put your code here
		//super.init(config);
		SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); //加上这行 
	}



你可能感兴趣的:(项目日记)