0

I have created a folder static inside the resources folder of my Spring Boot application. Inside the static folder I have an index.html file. Then I added this to my configuration:

protected void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**")
            .addResourceLocations("classpath:/static/");
}

Now I can access index.html at localhost:8080/index.html, but what I want to do is to access it at localhost:8080. I have tried this already:

@Override
protected void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("forward:/index.html");
}

But I get that "forward:/index.html"is not recognized by ServletDispatcher. Can someone help me with this? Thanks in advance.

EDIT

I solved the problem by deleting all my custom configuration, so the default configuration is available to my app. In my particular case, this works for me, but it wouldn't be bad to know how to achieve this with custom configurations. So this question is still open, everybody is welcome to give some input on the subject.

nskrobonja95
  • 39
  • 1
  • 8
  • Check out the answers to this SO question https://stackoverflow.com/questions/42393211/how-can-i-serve-static-html-from-spring-boot and this might also be useful https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot – karen Dec 12 '18 at 12:24

1 Answers1

0

I think it is not necessary to specify the extension and forward. You can try this:

public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("index");
}
  • I tried this too, but it still gives the same mistake. I even tried configuring the mvc-path in the properties file, with all kinds of different variations but with no results. – nskrobonja95 Dec 13 '18 at 07:28