Skip to content

Add a dedicated annotation to register filters and servlets #16500

Closed
@OrangeDog

Description

@OrangeDog

Sometimes you want to declare Filters 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions