Skip to content

Document that @Order cannot be used on a Filter's @Bean method to set the Filter's order #18266

@joca-bt

Description

@joca-bt

We've defined our custom filters (javax.servlet.Filter) through @Beans in a @Configuration class. Something like:

@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
    ...
    @Bean @Order(200)
    public Filter1 filter1() {
        return new Filter1();
    }
    @Bean @Order(100)
    public Filter2 filter2() {
        return new Filter2();
    }
    ...
}

However, the filters are being called in the order they appear in the code (Filter1 then Filter2) instead of the order defined by the annotations (Filter2 then Filter1). For other types of objects (non javax.servlet.Filter) the @Orders are being respected when the beans are injected.

If we define the filter and their ordering using @Component + @Order on the filter classes themselves or via @Beans of type FilterRegistrationBean + FilterRegistrationBean.setOrder() then the order is respected.

Is this anything specific to filters? Is this documented somewhere and we've missed that? Or is this an issue?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions