How to specify Filter execution order using Spring's Java Configuration?

Viewed 12839

I have the following piece of code in my initializer:

public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Filter[] getServletFilters() {

        DelegatingFilterProxy shiroFilter = new DelegatingFilterProxy("shiroFilter");
        shiroFilter.setTargetFilterLifecycle(true);

        return new Filter[]{new CorsFilter(),shiroFilter};
    }
}

I want CorsFilter to be executed before ShiroFilter. However, the Spring documentation doesn't say that the order in which the filters are executed is determined by their order in the returned array.

If it is, can someone please clarify it? If not, can someone suggest how do I guarantee the execution order of filters?

3 Answers

For someone who may want to use javax annotation instead of spring Order, @javax.annotation.Priority annotation also could be used instead of @Order like answer from "dit" above .

Related