2016-03-13 31 views
6

基本上,访问“/”和“/ a”正在浏览器上工作。 Acess“/ testme”不起作用。误差是Spring框架的圆形视图路径异常

2016年3月13日15:04:37.709 ERROR 1933 --- [IO-8080-EXEC-57] osboot.context.web.ErrorPageFilter:转发到从请求错误 页[/testmenull]由于例外[圆形视图路径 [testme.html]:将重新发回当前处理程序URL [/XXXX/testme.html]。检查你的ViewResolver设置! (提示:这 可能是一个未指定的视图的结果,由于默认视图名称 代。)

我做一个字符串的grep,但无法找到“的ViewResolver”。我不知道为什么“/”和“/ a”有效。任何想法?

中查看图像: enter image description here

所有XML文件: 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> 
+0

错误说检查你的viewResolver,你检查过吗?你可以粘贴xml配置吗? –

+0

没有viewResolver,因为我在所有文件中都做了一个字符串grep。我发布了web.xml和pom.xml。也是所有xml文件的图片。 – kenpeter

+0

所以它是一个Spring-Boot项目!我认为你已经与Spring-MVC和Spring-Boot项目混淆了。您必须在'src/main/resources'目录下缺少'testme.html'。 为什么是这个错误,请参阅[这个答案](http://stackoverflow.com/questions/18813615/how-to-avoid-the-circular-view-path-exception-with-spring-mvc-test)。 –

回答

13

的@RequestMapping的价值是“t” estme“,return的值也是”testme“,这样当你访问”/ testme“时,web会重新定向到”/ testme“。这将导致无尽的重定向到“/ testme”。

+0

这是从 - 圆形视图路径错误中保存的答案(!) – Andrius

5

如果您正在使用gradle,则必须添加: compile("org.springframework.boot:spring-boot-starter-thymeleaf"),或maven找到此依赖关系。

0

我认为,如果所有的HTML名称都是正确的,也许你需要声明这样的事情在你的MvcConfig类:

@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"); 
    }  
} 
1

如果不返回一个视图。但只有一个JSON,在响应中添加@ResponseBody有助于返回JSON值而不是视图。

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

0

这个问题谈到,由于在pom.xml中提到的循环依赖。如果您使用的是spring-boot-starter-freemaker,那么请避免使用spring-boot-starter-web。 spring-boot-starter-web已经是spring-boot-starter-freemaker的一部分。