圆形视图路径Spring启动教程

时间:2017-07-25 15:08:22

标签: java spring spring-boot

我实际上在学习Spring Boot。我按照指南进行操作,然后尝试这个:保护Web应用程序。

所以我已经制作了2个文件(hello.html / home.html),我想部署我的应用程序来查看它们,但是当我尝试访问localhost时:8080我收到此错误:

Circular view path [home]: would dispatch back to the current handler URL [/home] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

如果有人可以帮助我吗?这是我的代码:

src / main / java / com / society / MyApplication:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) throws Throwable {
        SpringApplication.run(CalamarApplication.class, args);
    }
}

的src /主/ JAVA / COM /社会/ MvcConfig.java

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/home").setViewName("home");
        registry.addViewController("/").setViewName("home");
        registry.addViewController("/hello").setViewName("hello");
        registry.addViewController("/login").setViewName("login");
    }

}

的src /主/资源/模板/ home.html的

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hello world!</h1>
    </body>
</html>

先谢谢。

0 个答案:

没有答案