Currently I have a web application where we are using web.xml to configure the application. The web.xml has welcome-file-list.
<web-app>
...
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
</web-app>
We are planning to use spring framework and use java class for application configuration.
class MyApplication extends WebApplicationInitializer {
public void onStartUp(ServletContext context){
...
}
}
How do I specify welcome-file-list in this java class?
This might help.
You can't
As specified in Java Doc
but you still need minimal configuration in web.xml , such as for
While developing Spring MVC application with pure Java Based Configuration, we can set the home page by making our application configuration class extending the WebMvcConfigurerAdapter class and override the addViewControllers method where we can set the default home page as described below.
It returns
home.jsp
view which can be served as home page. No need to create a custom controller logic to return the home page view.The JavaDoc for addViewControllers method says -
2nd way - For static HTML file home page we can use the code below in our configuration class. It will return
index.html
as a home page -3rd way - The request mapping "/" below will also return
home
view which can be served as a home page for an app. But the above ways are recommended.