How do I set home.jsp as my welcome page in java config based spring application

283 Views Asked by At

I am developing a spring application (annotation based configurations) in which index.jsp is my default welcome page. but now I don't want to display index.jsp as my welcome page and want to change it to home.jsp. how can I achieve this?

I tried below method from WebMvcConfigurerAdapter class

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("home");
}

it is not working.

1

There are 1 best solutions below

0
On

You need to forward the default mapping. Hope this may help you!

@Configuration
public class YourViewClass extends WebMvcConfigurerAdapter
{
    @Override
    public void addViewControllers( ViewControllerRegistry registry ) 
    {
        registry.addViewController( "/" ).setViewName( "forward:/yourhomepage.html" );
        registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
        super.addViewControllers( registry );
    }
}