I am developing a spring-boot rest service which contains two filters (implementing the javax.servlet.Filter
interface). While one filter should apply to all url patterns I want to configure the second filter to only apply to the url pattern /api/*
.
Currently I am doing this by using 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 if there is an annotation to do the same, considering there are annotations for setting the order of filters (@Order(..)
). I have tried using javax.servlet.annotation.WebFilter
but spring-boot does seem to ignore this annotation.
There isn't currently an annotation to do what you want. We do have an open issue to support @WebFilter
which we'd like to fix for Spring Boot 1.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With