Circular View Path Error, Spring MVC

I am trying to make a tutorial -> http://spring.io/guides/gs/serving-web-content/

When I run it, it says Circular View Path [greeting], why?

In the tutorial, one thing I don’t understand is what the following does and why it works:

return "greeting";

Code snippet:

package hello;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {
    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }
}
+4
source share
5 answers

You may have skipped a step by following the guide.

I will explain why you get the behavior you see and can decide what to do next.

You probably launched the application

SpringApplication.run(Application.class, args);

Application class 'main. - @EnableAutoConfiguration ( ) DispatcherServlet, UrlBasedViewResolver, prefix suffix .

@Controller,

return "greeting";

Spring UrlBasedViewResolver . greeting. , , Servlet API HttpServletRequest#getRequestDispatcher(String), . RequestDispatcher, .

, RequestDispatcher, Spring ( ) . , . , /greeting /greeting, @Controller, . Spring , , .. .

, @EnableAutoConfiguration , UrlBasedViewResolver InternalResourceViewResolver, .


Spring MVC.

+4

.pom,

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

public String greeting(){} public **@ResponseBody** String greeting(){},
, spring mvc , .

+2

/greeting, greeting. Spring, , - greeting, . @ResponseBody , .

@Controller
public class GreetingController {
    @RequestMapping("/greeting")
    public @ResponseBody String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }
}
0

I had the same error if followed with this . An error occurred in my maven dependencies, and I could fix this problem by deleting the .m2 folder and installing the dependencies again.

0
source

All Articles