Annotation for applying a filter in spring-boot to specific url patterns

I am developing a spring-boot service that contains two filters (implements the javax.servlet.Filter interface). Although one filter should apply to all url patterns, I want to configure the second filter only on the url /api/* pattern.

I am currently doing this using the following code:

 @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean registrationBean = new FilterRegistrationBean(); SecurityFilter securityFilter = new SecurityFilter(); registrationBean.setFilter(securityFilter); registrationBean.addUrlPatterns("/api/*"); return registrationBean; } } 

But my question is, is there an annotation to do the same, given that there are annotations for setting the order of the filters ( @Order(..) ). I tried using javax.servlet.annotation.WebFilter , but spring-boot seems to ignore this annotation.

+5
source share
1 answer

There is currently no annotation to do what you want. We have an open issue for @WebFilter support that we would like to fix for Spring Boot 1.3.

+7
source

Source: https://habr.com/ru/post/1212545/


All Articles