报错内容:
2020-03-10 09:11:47.525 [http-nio-82-exec-5] ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [test]: would dispatch back to the current handler URL [/test] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause
javax.servlet.ServletException: Circular view path [test]: would dispatch back to the current handler URL [/test] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
at org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:210)
原因:
1、view name名称和path请求方法名相同,就等于让自己转发给自己,陷入死循环
如:
@RequestMapping("/test")
public String hello() {
logger.trace("trace日志信息");
logger.debug("debug日志信息");
logger.info("info日志信息");
logger.warn("warn日志信息");
logger.error("error日志信息");
return "test";
}
解决方法:修改返回值
2、返回值为空,但方法上没有@ResponseBody
,会造成缺省转发
如:
@RequestMapping("/test")
public void hello() {
logger.trace("trace日志信息");
logger.debug("debug日志信息");
logger.info("info日志信息");
logger.warn("warn日志信息");
logger.error("error日志信息");
}
解决方法:方法上增加@ResponseBody
最近再学日志框架,写测试时候我报这个错误,错误原因为第二个。
其实我只是加上异步后,不报错了,但具体原因我还是不理解,如果有明白的,评论或者私信告诉我一下,为啥我浏览器打http://localhost:82/test请求hello()方法和
@ResponseBody
,注解有关系,直接敲不应该就是同步,然后报错找不到请求地址吗,怎么加上注解后,就不报错第二种错误了?