Im trying to migrate from XML to full java class based config in Spring MVC 4. What I did so far is the creation of a simple WebAppInitializer class and a WebConfig class.
But, I can't find a way to config my welcome page, Here's an excerpt from my old Web.xml
:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
Any help would be appreciated.
You do not need to do anything actually, spring automatically looks for index.html
file under src/main/webapp
, all you need to do is create a index.html
file and put it under this root.
You can do this by overriding the addViewControllers
method of WebMvcConfigurerAdapter
class.
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.myapp.controllers" })
public class ApplicationConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}
}
See my answer for more information.
Using this configuration you can set any filename as a welcome/home page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With