我正在使用Spring的@RestController
注释创建项目。一切正常,当我调用配置的URL路径时,如果发生了某些事情,我会收到格式良好的答案或错误。
但是,如果我在未定义的路径中调用服务,我会收到以下异常:
java.lang.StackOverflowError
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:229)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:592)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:229)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:592)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:229)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:592)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:229)
我知道发生此错误是因为我的请求无法映射到资源,但我想知道为什么我没有收到404 - Not found
错误类型?
我的DispatcherServlet配置如下:
ServletRegistration.Dynamic dispatcher =
servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
这是我的服务类的示例:
@RestController
@RequestMapping("/Genotypes")
public class GenotypeService {
... @Autowired objects here ...
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody List<Genotype> findGenotypesLike(@RequestParam(value="genName", required=false) String name, @RequestParam(value="like", defaultValue="false") Boolean like){
if(name == null){
return genotypeBO.findAllGenotypes();
}
return genotypeBO.findByName(name, like);
}
如果我致电http://localhost:8080/MyApp/Genotypes
,我会得到我的回复,但如果我致电http://localhost:8080/MyApp/SomethingNotMapped
,则会抛出异常而浏览器端的错误代码为500 - Internal Server Error
顺便说一下,我的应用程序在Apache Tomcat v7.0上运行。
提前感谢任何建议。