Monday, June 11, 2018

javax.servlet.ServletException: Circular view path [customers]

javax.servlet.ServletException: Circular view path [customers]: would dispatch back to the current handler URL [/customers] 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:209) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:147) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) ~[spring-webmvc-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.31.jar:8.5.31]


5 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This has nothing to do with Spring MVC testing.

    When you don't declare a ViewResolver, Spring registers a default InternalResourceViewResolver which creates instances of JstlView for rendering the View.

    The JstlView class extends InternalResourceView which is

    Wrapper for a JSP or other resource within the same web application. Exposes model objects as request attributes and forwards the request to the specified resource URL using a javax.servlet.RequestDispatcher.

    A URL for this view is supposed to specify a resource within the web application, suitable for RequestDispatcher's forward or include method.

    ReplyDelete
  3. In my case, I solved this problem by using @ResponseBody:

    @RequestMapping(value = "/contacts}", method = RequestMethod.GET, produces = {"application/json"})
    @ResponseStatus(HttpStatus.OK)
    @Transactional(value = "jpaTransactionManager")
    public @ResponseBody UserContact locateContact(@PathParam("contactID") String contactID)

    ReplyDelete
  4. I found an easy fix for this problem by creating a subclass of InternalResourceViewResolver that doesn't check for circular view paths:

    public class CustomViewResolver extends InternalResourceViewResolver {

    public CustomViewResolver () {
    super();
    }

    @Override
    protected AbstractUrlBasedView buildView(final String viewName) throws Exception {
    final InternalResourceView internalResourceView = (InternalResourceView) super.buildView(viewName);
    // the following prevents the circular view path check.
    internalResourceView.setPreventDispatchLoop(false);
    return internalResourceView;
    }
    }

    ReplyDelete
  5. I was working on a spring boot application which used angular js. I was getting circular path issue as well as data binding issues on my html. Event though my controller method was being executing the page dint show any data, and for one of the path it threw circular path issue mentioned above. I noticed that I had created a Controller with @Controller annotation (org.springframework.stereotype.Controller).
    My issue was resolved after I changed the annotation to @RestAnnotation (org.springframework.web.bind.annotation.RestController).

    ReplyDelete