标签:基于 release lan star start content path with bean
需求: 增加路由前缀
项目: 基于webflux 的 r2dbc 建立的 mqtt项目
解决方案: 一
# springboot 项目
# 版本 >=2.3.release
spring:
webflux:
base-path: "/project-name"
解决方案: 二
server:
servlet:
context-path: "/project-name"
@Bean
public WebFilter contextPathWebFilter() {
String contextPath = serverProperties.getServlet().getContextPath();
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);
};
}
标签:基于 release lan star start content path with bean
原文地址:https://www.cnblogs.com/akashicbrother/p/14744846.html