Issue
While working on a spring project I realized that I had three classes that were all in effect implementing WebApplicationInitializer
public class SpringSessionInitializer extends AbstractHttpSessionApplicationInitializer
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer
public class AnnotationWebAppInitializer implements WebApplicationInitializer
After looking at the three uses I saw that there was not a way for me to combine them so I had a few questions.
- Is the order in which these will execute consistent?
- If so is there a way to order them?
- If not will the body of any of the methods such as addInterceptors or ResourceResolvers, end up wiping out the settings from the others.
Solution
So Thanks to M.Deinum's comment as it led me to the answer. After playing around the @Order tag is the mechanism by which you control the order in which they load. The second part however is that yes the Order does matter. If you read the documentation of AbstractHttpSessionApplicationInitializer it states that it must me ordered before any other initializers that register filters. It also defaults its Order to 100. The reason it has to go first is it uses filters to retrieve the session from the cache database. If for example you order your AbstractSecurityWebApplicationInitializer to 50 you will no longer authenticate when switching servers because the spring security filters will execute before the filters that get the session from the database.
On the other side of this I removed a bug I was getting Spring-Tomcat Web Application java.lang.IllegalStateException, was solved by making my main initializer AnnotationWebAppInitializer go before the others.
Answered By - lvoelk