springboot报错would dispatch back to the current handler URL [/test] again. Check your Vie

报错内容:

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,注解有关系,直接敲不应该就是同步,然后报错找不到请求地址吗,怎么加上注解后,就不报错第二种错误了?

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值