Changing default welcome-page for spring-boot application deployed as a war
It's not too hard to do... you just need to forward the default mapping...
@Configuration
public class DefaultView extends WebMvcConfigurerAdapter{
@Override
public void addViewControllers( ViewControllerRegistry registry ) {
registry.addViewController( "/" ).setViewName( "forward:/yourpage.html" );
registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
super.addViewControllers( registry );
}
}
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);
}
}
Following Michael's tutorial, I was able to just map /
to my index.gsp
file.
@Controller
class Routes {
@RequestMapping({
"/",
"/bikes",
"/milages",
"/gallery",
"/tracks",
"/tracks/{id:\\w+}",
"/location",
"/about"
})
public String index() {
return "forward:/index.gsp";
}
}