创建spring boot maven应用程序时出现问题

时间:2015-07-09 04:19:00

标签: spring spring-boot

我正在使用spring boot创建一个基于Rest的Web服务,而在tomcat中部署却没有收到错误。但是当我尝试使用@RequestMapping注释的RestController方法并尝试打印字符串时在浏览器中。

收到错误:

输入例外报告

  

消息循环视图路径[错误]:将调度回当前   处理程序URL [/services-0.0.1-SNAPSHOT/error]再次。检查你的   ViewResolver设置! (提示:这可能是未指明的结果   视图,由于默认视图名称生成。)

说明服务器遇到内部错误,导致无法完成此请求。

例外

javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/services-0.0.1-SNAPSHOT/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
    org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:205)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:145)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:291)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration$MetricsFilter.doFilterInternal(MetricFilterAutoConfiguration.java:90)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
    org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:101)
    org.springframework.boot.context.web.ErrorPageFilter.forwardToErrorPage(ErrorPageFilter.java:173)
    org.springframework.boot.context.web.ErrorPageFilter.handleException(ErrorPageFilter.java:156)
    org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:119)
    org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:59)
    org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:101)

我无法弄清楚这个问题:(

在这方面的任何帮助都会很明显。

1 个答案:

答案 0 :(得分:0)

检查您的控制器类是否标有@RestController。如果没有,并且您只是使用@Controller对其进行注释,则必须将@Controller注释更改为@RestController。通过将@ResponseBody添加到控制器类或用于restful API的每个控制器方法,可以获得相同的结果。