Anton Anton - 7 months ago 7
Java Question

Spring Boot - how to serve one static html file for multiple routes in specified root

I need to serve static

html
file
(/src/main/resources/static/folder/index.html)
for all routes in specified root
(as example '/main/\**')
. I've tried to annotate controller method with
@RequestMapping("/main/**")
, but it works only for
'/main'
route, not for '
/main/foo'
,
'/main/foo/bar'
, etc...

So, how i can do this in spring boot?

Answer

I found this solution:

// application.properties
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html


// Controller for index.html
@Controller
public class IndexController {

    @RequestMapping({"/login", "/main/**"})
    public String index() {
        return "index";
    }
}
Comments