ApplicationContextInitializer and contextConfigLocation ?

Brent Putman putmanb at georgetown.edu
Thu Jun 12 17:31:19 EDT 2014


On 6/12/14 2:37 PM, Tom Zeller wrote:
> Hey Brent,
>
> It looks to me like contextConfigLocation property replacement does
> not work for property sources added by an
> ApplicationContextInitializer. Do you know if that is true ?

No, I've not thought about that specifically.  However, thinking about
it now, I wouldn't necessarily expect it to work. It only works in
application context XML because you load the property placeholder
configurer to do the property replacement there.  (See below, it looks
like property replacement does happen on the location values but it's
happening too early, read on...)

However I *think* you can make it work right in your
ApplicationContextInitializer impl.  Looking at their code in
org.springframework.web.context.ContextLoader#configureAndRefreshWebApplicationContext,
they pull that init param out of web.xml and set it on the context prior
to calling the ACIs and doing the refresh().

So I imagine you could do your own property replacement on the context
config location string(s) by using ConfigurableWebApplicationContext
#getConfigLocations() and #setConfigLocations(). 

Actually, it looks like setConfigLocations() might actually do property
replacement at the time it is called - but in the init of the root web
application context that is called before the ACIs get called, so your
custom PropertySource isn't there yet.  Forcing the property replacement
on those in your ACI might be as simple as calling
context.setConfigLocations(context.getConfigLocations()) *after* you've
added your custom property source, to force that property replacement to
happen again with the newly updated Environment.

If not, then I'm pretty sure you can just manually do replacement on the
values from getConfigLocations() and set them back using
setConfigLocation(). 

--Brent






-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20140612/6cfa5d21/attachment.html 


More information about the dev mailing list