Juan Medina is right. I just want to make it even more understandable and provide a link .
In fact, you just need to add the RouterFunction component to handle static resources. You do not need to implement your own RouterFunction, because RouterFunctions.resources("/**", new ClassPathResource("static/")); gives what you want.
All I do is add this piece of code:
@Bean RouterFunction<ServerResponse> staticResourceRouter(){ return RouterFunctions.resources("/**", new ClassPathResource("static/")); }
All unrecognized requests will go to the static router.
Peter YuChen waNgamer
source share