Spring Boot + MVC



  • Spring boot project from the web. I'm trying to get a test page. To this end:

    1. I wrote the counterer.

    2. MVC

    3. In the catalogue of webapp/WEB-INF/view/ created page jsp: index.jsp

    Controller reference code:

    @Controller
    public class HomeController {
    
    @RequestMapping(name = "/", method = RequestMethod.GET)
    public String home() {
        return "index";
    }
    

    }

    Reference MVC configuration code:

    @EnableWebMvc
    @Configuration
    public class MvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        super.addViewControllers(registry);
        registry.addViewController("/").setViewName("index");
    }
    
    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/view/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
    

    }

    I'm running a project, it's going to be all right. I'm going to the localhost:808080 will make a mistake:

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

    Please, I can't make a mistake all day.



  • I don't know why, but by switching the annot of @Controller to @RestController, the problem has gone.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2