I have a single-page webapp with a spring java-config setup. Currently, I have to enter localhost/resources/index.html
to get to my app. I would like to set it up so I can just enter localhost
and then see the index.html
page.
This is my WebConfig. I don't know if this is where I need to be messing with stuff but I tried adding registry.addResourceHandler("/").addResourceLocations("resources/index.html")
but that didn't work. Any ideas? Am I going about this the wrong way?
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.example.web")
public class WebConfiguration extends WebMvcConfigurerAdapter
{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
registry.addResourceHandler("/resources/**").addResourceLocations("resources/").setCachePeriod(31556926);
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
...
}
localhost is your local server. You cannot have bring up your app. Whenever you deploy your app it is a context on your localhost. eg you developed a web app with the name HelloWorld then your minimum URL to reach the app would be http://localhost :/HelloWorld In order to default to index.html add the following, if not already present, to your web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.