2

As we know, nginx or apache hosting servers, when visitors go to a URL that requests a directory, such as http://example.com/products, the web server looks for a file in the products directory named index.html. If index.html exists, its contents would be displayed.

How can I configure spring boot to get the same effect?

Please note that I don't mean to set a default welcome page. I'd like to display index.html under every specific directory.

What I've done is as following:

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

This can help me get what I want, but seems very stupid if I have lots of such folders. So I wonder if it can be realized automatically like nginx or apache servers. Thanks so much for any suggestion.

sincosmos
  • 176
  • 1
  • 3
  • 13
  • Thats usually the part of a webserver as you mentioned. But you could write an interceptor that checks if there is a `index.html` for a given `uri` available an then return it before even acController is called. – saw303 Nov 17 '17 at 10:27
  • @saw303 yes, I'd better find a way to relocate these static pages to my nginx server. And if I have to render the view, I could take use of an interceptor. – sincosmos Nov 17 '17 at 10:36

0 Answers0