I know that in spring I must define welcome-file, which should be outside of WEB-INF folder, so I define it like this:
web.xml:
See my answer: https://stackoverflow.com/a/15551678/173149 or just:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
<url-pattern>/index.htm</url-pattern> <<== *1*
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.htm</welcome-file> <<== *2*
</welcome-file-list>
In case of java configuration you can override two methods in class that extends WebMvcConfigurerAdapter
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("/index");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
If you wanna serve index.html explicitly, turn it into a resource override a method in the same class as below:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/index.html").addResourceLocations("/WEB-INF/views/index.html");
}
Of course addResourceLocations
must follows the folder choosen to hold your views.
See these samples
@RequestMapping({"/index", "/"})
and
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
worked for me.
Try using
<welcome-file-list>
<welcome-file>/index</welcome-file>
</welcome-file-list>