我一直在试图找到一种方法来为webflux应用程序设置上下文路径.我知道我可以使用它进行配置
server.servlet.context-path
Run Code Online (Sandbox Code Playgroud)
如果我部署一个servlet,但我想用webflux实现它,而不必显式添加每个路由的路径或使用MVC.
小智 30
根据这个
属性名称中有servlet,这应该是一个不适用于 webflux 的提示。
使用 springboot v2.3,你可以把它放在你的属性文件中
spring.webflux.base-path=/your-path
Run Code Online (Sandbox Code Playgroud)
发行说明参考:https : //github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#configurable-base-path-for-webflux-applications
您可以使用Web过滤器使WebFlux支持contextPath
@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);
};
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我遇到了类似的问题spring.webflux.base-path(似乎没有按预期工作)webflux-reactive-spring-web,我意识到我禁用了自动配置。
手动解决方法是:
@Bean
public WebFluxProperties webFluxProperties(){
return new WebFluxProperties();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4430 次 |
| 最近记录: |