Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 756
flomm Avatar asked Feb 03 '15 16:02

flomm


1 Answers

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.

like image 190
Phil Webb Avatar answered Oct 03 '22 00:10

Phil Webb