Spring PropertySource and Environment
Brent Putman
putmanb at georgetown.edu
Tue May 13 16:30:13 EDT 2014
On 5/13/14 1:26 PM, Tom Zeller wrote:
> Thanks Brent.
>
> It was not clear to me how to "attach" the custom application context
> initializer to an application context, but the following code to do so
> manually helped me get clearer :
>
> GenericXmlApplicationContext applicationContext = new
> GenericXmlApplicationContext();
> ApplicationContextInitializer myInitializer = new MyInitializer();
> myInitializer.initialize(applicationContext);
> applicationContext.load("/conf/applicationContext.xml");
> applicationContext.refresh();
That looks mostly right, although in the code I've seen, the
initializers are invoked just before the refresh(). So after any config
resource loading, etc.
To be clear, you shouldn't have to actually write any code like this, at
least for the root web app context or Spring MVC dispatcher servlet
context. You just declare the initializer in web.xml, and the Spring
ServletContextListener (ContextLoaderListener) does the rest.
More information about the dev
mailing list