Filters as the name suggest used to perform filtering on either the request to a resource or on the response from a resource, or both. Spring Boot provides few options to register custom filters in the Spring Boot application.
Register the custom Filter using FilterRegistrationBean.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@Configuration publicclassAppConfig{
@Bean public FilterRegistrationBean<CustomURLFilter> filterRegistrationBean(){ FilterRegistrationBean<CustomURLFilter> registrationBean = new FilterRegistrationBean(); CustomURLFilter customURLFilter = new CustomURLFilter();
registrationBean.setFilter(customURLFilter); registrationBean.addUrlPatterns("/test/*"); registrationBean.setOrder(2); // set precedence return registrationBean; } }