处理webflux 项目 增加 content-path


需求: 增加路由前缀
项目: 基于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);
    };
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM