Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve static content using Webflux?

Tags:

I am learning webflux and I would like to know how to serve static content on a MicroService using webflux but I didn´t find information to do it.

like image 707
jabrena Avatar asked Apr 25 '17 22:04

jabrena


People also ask

Which bean serve static resources in spring?

Spring Boot comes with a pre-configured implementation of ResourceHttpRequestHandler to facilitate serving static resources. By default, this handler serves static content from any of the /static, /public, /resources, and /META-INF/resources directories that are on the classpath.

Is WebFlux better than MVC?

Moreover, Spring WebFlux supports reactive backpressure, so we have more control over how we should react to fast producers than both Spring MVC Async and Spring MVC. Spring Flux also has a tangible shift towards functional coding style and declarative API decomposition thanks to Reactor API behind it.

Where do static files go in spring boot?

The file is located in the src/main/resources/static directory, which is a default directory where Spring looks for static content. In the link tag we refer to the main. css static resource, which is located in the src/main/resources/static/css directory. In the main.

How do I register a static assets folder in spring boot?

Step 1: Move images folder from src/main/resources/static/images to src/main/webapp/WEB-INF/images. Step 2: Look up SpringBootMainApplication. java add code @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { // Register resource handler for images registry.


1 Answers

Try this

RouterFunction router = resources("/**", new ClassPathResource("public/")); 

UPDATE: Don't forget to specify a name of the static file in the URL when accessing it from outside, like localhost:8080/index.html

like image 50
Juan Medina Avatar answered Sep 22 '22 06:09

Juan Medina