Changing default welcome-page for spring-boot application deployed as a war

前端 未结 4 1971
梦谈多话
梦谈多话 2020-12-01 08:21

I was trying to find a way to change the default welcome-page for a spring-boot application that is being deployed as a war in production but I can\'t find a way to do it wi

4条回答
  •  春和景丽
    2020-12-01 08:45

    Well, a few years passed since the last answer - and code evolves..

    This won't work on Spring 5 / Java 8+, you should implement the interface and override the default method.

    import org.springframework.core.Ordered;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    @Configuration
    public class DefaultViewConfig implements WebMvcConfigurer {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("/homepage.html");
            registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        }
    }
    

提交回复
热议问题