Closed
Description
Sometimes you want to declare Filter
s as @Beans
in order to have them managed and dependencies injected etc. but do not want them to be automatically registered.
This can be a problem particularly when working with Spring Security. Though this will apply in any situation with multiple filter chains.
Currently you have to declare a FilterRegistrationBean
for every filter with setEnabled(false)
, which can get very tedious and can be a maintenance problem.
I propose a new annotation-based method to exempt filter beans from autoregistration. For maximum utility, perhaps by implementing FilterRegistrationBean
(or just RegistrationBean
) wholly as an annotation?
@Bean
@FilterRegistration(enabled=false)
public Filter manualFilter() { ... }
@Bean
@FilterRegistration(order=200, urlPatterns={"/path/**"})
public Filter automaticFilter() { ... }
Related: #2173