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

前端 未结 4 1984
梦谈多话
梦谈多话 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 09:00

    I am doing it as follows.

    package org.gwtproject.tutorial.configuration;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.Ordered;
    import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    /**
     * Configure the welcome page 
     * 
     */
    @Configuration
    public class SpringBootWelcomePageConfiguration extends WebMvcConfigurerAdapter implements WebMvcConfigurer {
    
        /**
         * redirect a user to the welcome page when he visits tha app without a
         * destination url.
         */
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("forward:/ForExampleAGwtEntrypoint.html");
            registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
            super.addViewControllers(registry);
        }
    }
    

提交回复
热议问题