I have a web application using Spring 4 and servlet-api 3.1 in which I am using AbstractAnnotationConfigDispatcherServletInitializer to initialize the DispatcherServlet and ContextLoaderListener via annotated @Configuration java-config Spring app contexts. Environment-specific configuration of the application is achieved using a PropertySourcesPlaceholderConfigurer with @PropertySource annotations. This all works nicely. My question is:
I am now in the position of overriding Filter[] getServletFilters() to add filters to the servlet context. However, for the init-param values of some of these filters, I would really like to be able to access some of the aforementioned environment-specific configuration values. Unfortunately, because the environments stuff is post-processing in the application contexts, it appears that I am unable to simply re-use the rather neat Spring configuration injection here. If at all possible, I would like to avoid either hard-coding values that are elsewhere dynamically configured or having to effectively duplicate the environment config logic provided by Spring.
Has anyone come up with a neat way to inject configured values that are shared with an app context into a WebApplicationInitializer?