Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
private final String V1_URL_PATTERN = "/v1/*";
private final String V2_URL_PATTERN = "/v2/*";
@Bean
public FilterRegistrationBean<RequestIdFilter> requestIdFilter() {
FilterRegistrationBean<RequestIdFilter> filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new RequestIdFilter());
filterRegistrationBean.addUrlPatterns(V1_URL_PATTERN, V2_URL_PATTERN);
return filterRegistrationBean;
but it is impossible to do this, since RequestIdFilter implements WebFilter...
How to specify the necessary paths to filters using WebFilter Spring WebFlux?
In here, you have just declared this filter as just a bean and added the Order with @Order(). Adding @Order is optional.
What you have done incorrectly here is registering the webFilter as FilterRegistrationBean.
Here, implicitly, you are using Webflux Config as Spring boot is using WebFlux Config to register webflux. When using the WebFlux Config, the way of registering a WebFilter is declaring it as a Spring bean. Optionally you can declare order as well.
Here is the correct code
@Configuration
public class RequestIdFilter implements WebFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
//my logic
return chain.filter(exchange);
@Configuration
class FilterConfig {
private final String V1_URL_PATTERN = "/v1/*";
private final String V2_URL_PATTERN = "/v2/*";
@Bean
public RequestIdFilter requestIdFilter() {
return new RequestIdFilter();
According to this it is enough to declare the WebFilter
I think you need a HandlerFilterFunctions
The WebFlux framework provides two types of filters: WebFilters and HandlerFilterFunctions. HandlerFilterFunction implementations will only work for Router-based ones.
There is an example here
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.