类似于springmvc项目一样,需要增加项目路由前缀,webflux需要特殊配置下,直接在yml文件配置路由前缀可能会不生效。
解决方案如下:
@Bean
public WebFilter contextPathWebFilter() {
String contextPath = "/aida_meeting_service";
return (exchange, chain) -> {
ServerHttpRequest request = exchange.getRequest();
if (request.getURI().getPath().startsWith(contextPath)) {
return chain.filter(
exchange.mutate()
.request(request.mutate().contextPath(contextPath).build())
.build());
}
return chain.filter(exchange);
};
}
可以将contextPath配置到yml文件中。
server:
servlet:
context-path: "/aida_meeting_service"
获取contextPath的方式换成
String contextPath = serverProperties.getServlet().getContextPath();