Spring boot error: Check your ViewResolver setup, springviewresolver

Source: Internet
Author: User

Spring boot error: Check your ViewResolver setup, springviewresolver

Whitelabel Error Page

This application has no explicit mapping for/error, so you are seeing this as a fallback.

Fri Mar 23 10:34:26 CST 2018
There was an unexpected error (type = Internal Server Error, status = 500 ).
Circular view path [index]: wocould dispatch back to the current handler URL [/home/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation .)

Solution:

Method 1Add Annotations to the request method:@ ResponseBody, No template file required

@RequestMapping("/home")@Controller()public class HomeController {    @ResponseBody    @RequestMapping("/index")    public String index() {        return "index";    }}

Method 2. Use thymeleaf Template
Add a static template dependency to the dependencies element of pom. xml.

    <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-thymeleaf</artifactId>    </dependency>

Create an html template file in resources/templates/. The file name is the same as the string of the Request Method return. The extension is html: index.html.

<!DOCTYPE html>
@RequestMapping("/home")@Controller()public class HomeController {    @RequestMapping("/index")    public String index(HashMap<String,Object> map) {        map.put("data","index.html");        return "index";    }}

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.