Exclude the round-trip path using the Spring framework

Mostly access to "/" and "/ a" works in the browser. Acess "/ testme" does not work. Error

2016-03-13 15: 04: 37.709 ERROR 1933 --- [io-8080-exec-57] osboot.context.web.ErrorPageFilter: sending to the page with an error from the request [/ testmenull] due to exception [Circular view path [testme.html]: will send back the URL of the current handler [/XXXX/testme.html] again. Check out the ViewResolver setup! (Hint: this may be the result of an undefined view due to the name of the default view generation.)]

I am doing a grep line but cannot find "ViewResolver". I have no idea why "/" and "/ a" work. Any idea?

See image for more information: 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> 
+6
source share
5 answers

the @RequestMapping value is "testme", and the return value is also "testme", so when you access "/ testme", the network is redirected to "/ testme" again. This will result in an endless redirect to "/ testme".

+13
source

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

+5
source

If you do not return the submission. But only JSON, adding @ResponseBody to the answer, helps return the JSON value, not the view.

For example: @RequestMapping(value="/getList",method = RequestMethod.GET) public @ResponseBody List<LOne> getLOne(){

+1
source

I think if all the HTML names are correct, maybe you need to declare something like this in your MvcConfig class:

 @Configuration public class MvcConfig extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/home").setViewName("home"); registry.addViewController("/usuario/perfil").setViewName("usuario/perfil"); registry.addViewController("/").setViewName("home"); registry.addViewController("/testme").setViewName("testme"); registry.addViewController("/test").setViewName("test"); registry.addViewController("/login").setViewName("login"); } } 
0
source

This issue occurs due to the circular dependencies mentioned in pom.xml. If you use spring-boot-starter-freemaker, then do not use spring-boot-starter-web. spring-boot-starter-web is already part of spring-boot-starter-freemaker.

0
source

All Articles