昨天在用postmen测试接口时报”java.lang.InstantiationException“错误,决定记录下来以及给大家参考;错误提示如下:
七月 26, 2019 8:41:10 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springMVC] in context with path [/paperBagPrinting] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.http.HttpServlet]: Is it an abstract class?; nested exception is java.lang.InstantiationException] with root cause
java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
最后发现原来是在import的时候出错了,下面是加零建的类
public Map<String,Object> getCourseCode
(HttpServletRequest Request,HttpServletResponse Response,
String courseName){
}
这是我写的import语句,在编译的时候没报错,运行的时候会报错:import javax.servlet.http.HttpServlet;
正确的写法应该是:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
改正错误后就可以运行了。