spring-boot-starter-webflux(Spring Boot v2.0.0.M2)已像中一样进行配置,spring-boot- starter-web以在资源中的静态文件夹中提供静态内容。但是它不会转发到index.html。在Spring MVC中,可以这样配置:
spring-boot-starter-webflux
spring-boot- starter-web
@Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("forward:/index.html"); }
在Spring Webflux中如何做?
在WebFilter中执行:
@Component public class CustomWebFilter implements WebFilter { @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getURI().getPath().equals("/")) { return chain.filter(exchange.mutate().request(exchange.getRequest().mutate().path("/index.html").build()).build()); } return chain.filter(exchange); } }