There are multiple solutions to create a filter in your Spring Boot application.
See the following question for multiple options: How to add a filter class in Spring Boot?
I prefer creating a FilterRegistrationBean in my application context, it can have similar configuration then the config you would write to web.xml using plain Spring MVC.
From the above question registering a filter can be done as follows:
@Bean
public FilterRegistrationBean someFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(someFilter());
registration.addUrlPatterns("/url/*");
registration.addInitParameter("paramName", "paramValue");
registration.setName("someFilter");
registration.setOrder(1);
return registration;
}
public Filter someFilter() {
return new SomeFilter();
}
If you need multiple filters, just create a bean for each.
Spring Boot will automatically find these beans, and configure the filters for you.