Spring boot doesn't map folder requests to `index.html` files

前端 未结 4 1164
一个人的身影
一个人的身影 2021-01-01 11:58

I\'ve got static folder with following structure:

index.html
docs/index.html

Spring Boot correctly maps reque

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 12:30

    After Java 8 introduced Default Methods in Interfaces, WebMvcConfigurerAdapter has been deprecated in Spring 5 / Spring Boot 2.

    Using it will now raise the warning:

    The type WebMvcConfigurerAdapter is deprecated

    Hence, to make @hzpz's solution work again, we need to change it as follows:

    @Configuration
    public class CustomWebMvcConfigurer implements WebMvcConfigurer {
    
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/docs").setViewName("redirect:/docs/");
            registry.addViewController("/docs/").setViewName("forward:/docs/index.html");
        }
    }
    

提交回复
热议问题