Implement custom values ​​in Spring 4 WebApplicationInitializer

I have a web application using Spring 4 and servlet-api 3.1 in which I use Spring's java-config application AbstractAnnotationConfigDispatcherServletInitializerto initialize DispatcherServletand ContextLoaderListenerthrough the annotated application context @Configuration. Application configuration for a specific environment is achieved using annotations PropertySourcesPlaceholderConfigurerc @PropertySource. All of this works great. My question is:

Now I can override 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 have access to some of the above configuration values ​​for a particular environment. Unfortunately, since the environment is post-processing in application contexts, it seems that I can't just reuse the pretty neat Spring configuration injection here. If at all possible, I would like to avoid either hard-coding values ​​that are dynamically configured elsewhere, or to effectively duplicate the environment configuration logic provided by Spring.

Has anyone come up with a neat way to enter customized values ​​that are shared by the application context in WebApplicationInitializer?

+4
source share

All Articles