在Spring Reactive Web(WebFlux)中,将所有端点的前缀更改为”/api”或其他前缀。

huangapple go评论74阅读模式
英文:

Prefix all endpoints with "/api" or another prefix, in spring reactive web (webflux)

问题

我在一个Spring响应式Web项目中有一组RestControllers,并且我想在不同的环境中为所有控制器添加前缀“api”或“test-api”。

我尝试使用server.servlet.context-path=/api,但在运行在Netty服务器上的Spring响应式Web(Webflux)中不起作用。

英文:

I have a set of RestControllers in a spring reactive web project and I want to prefix all of the controllers with "api" or "test-api" in different environments.

I have tried to use server.servlet.context-path=/api and it's not working with spring reactive web (webflux) running on Netty server

答案1

得分: 6

以下属性在Spring Boot 2.3中被添加,用于在WebFlux中实现此功能:

spring.webflux.base-path

发布说明:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#configurable-base-path-for-webflux-applications

英文:

The following property was added in spring boot 2.3 to achieve this with webflux

spring.webflux.base-path

Release Notes: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#configurable-base-path-for-webflux-applications

答案2

得分: 2

你尝试过在 @RequestMapping 中使用占位符,例如 @RequestMapping("${foo.bar}") 吗?

谢谢

英文:

Have you tried using a placeholders in @RequestMapping, like for example @RequestMapping("${foo.bar}") ?

Thank you

huangapple
  • 本文由 发表于 2020年10月16日 19:52:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64388664.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定