小编Shr*_*ath的帖子

Spring Webflux WebFilterChain 中的 URL 模式过滤

我正在尝试在 Spring Webflux 中编写一个过滤器,但无法找到仅将过滤器应用于某些 URL 模式的选项。在 Spring MVC 世界中,这可以通过使用来实现

FilterRegistrationBean.addUrlPatterns("/protected/*");
Run Code Online (Sandbox Code Playgroud)

但我无法在 webflux 世界中找到它的等价物。

作为解决方法,我使用以下方法,但这显然不是正确的方法

String path = serverWebExchange.getRequest().getURI().getPath();
if(path.contains("/protected/"))
<do-something>
Run Code Online (Sandbox Code Playgroud)

是否有任何 Spring Webflux 本机 URL 模式匹配方法WebFilterChain可以用来将过滤器仅应用于一组特定的 URL?谢谢 !

java spring-security spring-boot spring-webflux spring-filter

5
推荐指数
1
解决办法
2874
查看次数