Configure ViewResolver with Spring Boot and annotations gives No mapping found for HTTP request with URI error

前端 未结 3 1345
深忆病人
深忆病人 2020-11-27 14:36

I\'m trying to make \"hello world\" application with gradle, spring boot and spring mvc with the simplest view resolver and html.

I started from the thymeleaf spring

3条回答
  •  温柔的废话
    2020-11-27 15:00

    You only need to enable the default servlet, this is done by adding the following to your MvcConfiguration:

    @Configuration
    @EnableWebMvc
    public class MvcConfiguration extends WebMvcConfigurerAdapter{
        @Bean
        public ViewResolver getViewResolver() {
            InternalResourceViewResolver resolver = new InternalResourceViewResolver();
            resolver.setPrefix("/WEB-INF/");
            resolver.setSuffix(".html");
            return resolver;
        }
    
        @Override
        public void configureDefaultServletHandling(
                DefaultServletHandlerConfigurer configurer) {
            configurer.enable();
        }    
    }
    

    Essentially what is happening is Spring does not know how to handle the handling of such content natively(could be a jsp say), and to this configuration is the way to tell it to delegate it to the container.

提交回复
热议问题