Reputation: 26441
I use Spring REST Docs to generate documentation. Then I put it inside fat jar.
Location of file within jar:
/BOOT-INF/classes/static/docs/index.html
How I can serve such file using webflux?
I've tried to put resources
in RouterFunctionDsl
:
internal class MyRoutes() {
fun router() = router {
"/foo".nest {
resources("/docs", ClassPathResource("docs/"))
}
}
}
unfortunately with no luck
Upvotes: 1
Views: 1020
Reputation: 26441
It seems that I don't need to add any resources
. Serving static files works out of box (in Spring Boot)
According to the docs: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-webflux-static-content
Upvotes: 0
Reputation: 59086
It looks like a typo in your code sample, it should probably be
ClassPathResource("static/docs/")
I guess you were confused by the default locations used by Spring Boot to serve static locations. If you look at the Spring Boot common application properties section in the reference documentation, you'll see that the default value for the resource locations in WebFlux and MVC are the following:
classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
So the /static
prefix is not automatically added, it's a Spring Boot convention.
Upvotes: 1