spring boot 2 + netty + servlet.context-path + 不工作

7 spring-boot spring-webflux

我正在尝试使用 spring-boot-starter-webflux 和反应式 Netty 创建一个 spring-boot-2 REST api。我正在尝试根据在 Spring-Boot-2 中定义的 application.yml 中定义的新属性设置上下文路径。

server.servlet.context-path: /api  # Define the server context path
Run Code Online (Sandbox Code Playgroud)

然而它看起来像 Webflux,Netty 不使用/识别 application.yml 中定义的这个属性。

如果我使用 spring-boot-starter-web 和 Tomcat 作为默认服务器,那么它可以正常工作并正确识别上下文路径。

Spring Boot 2 文档中没有找到任何关于 Netty 上下文路径的内容

Spring Boot Version = 2.0.3.RELEASE
Run Code Online (Sandbox Code Playgroud)

如果我错过了什么,或者这是 Webflux Netty 的默认行为,请告诉我?

小智 6

在 spring boot 2.3.x 中,您可以设置 spring.webflux.base-path 属性


kj0*_*007 5

配置上下文路径是特定于 servlet 的。使用 WebFlux 时,配置属性被重命名为 server.servlet.context-path 并且仅用于基于 servlet 的部署。

您可以阅读以下线程,了解如何处理 webflux 中的上下文路径,请参阅评论

https://github.com/spring-projects/spring-boot/issues/10129#issuecomment-351953449

Webflux 上下文路径问题线程