3

I am using Spring Boot 2.0.0 M1 with WebFlux to build my sample web application. After succeeding with REST endpoints I've decided to add some views to my application. I've decided to use Thymeleaf 3.x version. I know that Spring serves static content from 4 default location:

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

I've decided to go with second example so my css file is in /resources/static/css/. However after loading my page .css file was not found. This is a screenshot from my IDE: IDE view

I am not providing my own configuration for static directory I just want to use default one. What might be important is the fact that templates are loading just fine from the /resources/templates/ directory.

Css file is loaded like this:

<link data-th-href="@{css/bootstrap.min.css}" rel="stylesheet">

App is not using normal Controller class instead I've provided function as a Bean to define my router:

@Bean
RouterFunction<?> router(final GeneratorHandler generatorHandler) {
    return route(GET("/generate"), handler::render);
}

Any ideas what's wrong here?

General_Code
  • 239
  • 1
  • 4
  • 12
  • Possible duplicate of [How to serve static content using Webflux?](https://stackoverflow.com/questions/43622053/how-to-serve-static-content-using-webflux) – kinjelom Jun 12 '17 at 12:57

1 Answers1

1

I've found the right solution. In your RouterFunction you need to use:

return resources("/**", new ClassPathResource("/static/"))

This will set your static directory to:

:classpath/static
General_Code
  • 239
  • 1
  • 4
  • 12