It seems that since spring-boot-starter-web version 3.1.0 FilterRegistrationBean setUrlPatterns gets ignored when used like:

@Configuration
@RequiredArgsConstructor
public class FilterConfiguration {

    @Bean
    public FilterRegistrationBean<RequestFilter> filterRegistrationBean() {
        FilterRegistrationBean<RequestFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        RequestFilter filter = new RequestFilter();
        filterRegistrationBean.setFilter(filter);
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setUrlPatterns(List.of("/test/v1/*", "/test/v2/*", "/test/v3/*"));
        return filterRegistrationBean;
    }
}

RequestFilter is a filter that extends OncePerRequestFilter. Instead of following the urlPatterns, the filter gets applied to all URLs.

Comment From: mhalbritter

I can't reproduce this, tested with Boot 3.1.5. If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

Comment From: Foteno

At the moment I cannot provide with the working sample, but I see the problem. Since 3.1.0 if @Component annotation is on the filter class then it will be applied to all URLs, but if @Component is not present, then everything is fine.

Not sure if this was appropriate way to use it, or if this is a bug after all.

EDIT: do notify, if minimal sample should be provided later

Comment From: bclozel

@Foteno what you're describing here is the expected behavior. If the filter is scanned by the application then it will be applied without path mapping restrictions.

I'm closing this issue as a result. Thanks!

Comment From: Foteno

Understood, thank you.