Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular view path exception with Spring framework

Basically, access "/" and "/a" are working on browser. Acess "/testme" is not working. Error is

2016-03-13 15:04:37.709 ERROR 1933 --- [io-8080-exec-57] o.s.boot.context.web.ErrorPageFilter : Forwarding to error page from request [/testmenull] due to exception [Circular view path [testme.html]: would dispatch back to the current handler URL [/XXXX/testme.html] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)]

I do a string grep, but cannot found "ViewResolver". I have no idea why "/" and "/a" work. Any idea?

See image for more: enter image description here

All xml files: enter image description here

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.xxxxx</groupId>
  <artifactId>Monitor</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <!--<name>Monitor</name>-->
  <url>http://maven.apache.org</url>

  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.1.9.RELEASE</version>
  </parent>

  <dependencies>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
          <groupId>javax.websocket</groupId>
          <artifactId>javax.websocket-api</artifactId>
          <version>1.1</version>
          <scope>provided</scope> <!--for web socket-->
      </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
      </dependency>
      <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.31</version>
      </dependency>
      <dependency>
          <groupId>org.springframework.hateoas</groupId>
          <artifactId>spring-hateoas</artifactId>
      </dependency>
      <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.3</version>
      </dependency>
      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
      </dependency>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
      </dependency>
  </dependencies>

  <build>
      <finalName>Monitor</finalName>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.1</version>
              <configuration>
                  <compilerVersion>1.7</compilerVersion>
                  <source>1.7</source>
                  <target>1.7</target>
              </configuration>
          </plugin>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
          <!--<plugin>-->
              <!--<groupId>org.apache.maven.plugins</groupId>-->
              <!--<artifactId>maven-source-plugin</artifactId>-->
              <!--<executions>-->
                  <!--<execution>-->
                      <!--<id>attach-sources</id>-->
                      <!--<goals>-->
                          <!--<goal>jar</goal>-->
                      <!--</goals>-->
                  <!--</execution>-->
              <!--</executions>-->
          <!--</plugin>-->
      </plugins>
      <resources>
          <resource>
              <directory>${basedir}/src/main/resources</directory>
          </resource>
          <resource>
              <directory>${basedir}/src/main/java</directory>
          </resource>
      </resources>
  </build>
</project>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
</web-app>
like image 600
kenpeter Avatar asked Mar 13 '16 04:03

kenpeter


4 Answers

the value of @RequestMapping is "testme" and the value of return is also "testme" so that when you access "/testme", the web will redirect to "/testme" again. This will lead to endless redirection to "/testme".

like image 51
Boli-CS Avatar answered Oct 17 '22 07:10

Boli-CS


Tried all the above suggestions and it didn't work for me. But the issue was resolved when I changed the annotation on my controller class from @Controller to @RestController (which is a combination of @Controller and @ResponseBody).

like image 22
ECM ECM Avatar answered Oct 17 '22 06:10

ECM ECM


If you are using gradle you have to add: compile("org.springframework.boot:spring-boot-starter-thymeleaf"), or maven find this dependency.

like image 7
MACCXpace Avatar answered Oct 17 '22 06:10

MACCXpace


If you are not returning a view. But only a JSON, adding @ResponseBody to the response helps returning a JSON value rather than a view.

Eg:

@RequestMapping(value="/getList",method = RequestMethod.GET)
public @ResponseBody List<LOne> getLOne(){
like image 3
User-8017771 Avatar answered Oct 17 '22 06:10

User-8017771