Search code examples
spring-webfluxstatic-files

Serving content from jar using webflux?


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


Solution

  • 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