Spring PropertySource and Environment

Brent Putman putmanb at georgetown.edu
Thu May 8 18:32:06 EDT 2014


On 5/8/14 3:16 PM, Cantor, Scott wrote:
>
> The question I guess is partly whether properties inherit or not.

Just spend some more time looking at this.  I'm pretty sure they do
effectively inherit.  Looks like in general when
ConfigurableApplicationContext#setParent(parentContext), this code from
AbstractApplicationContext is called:


public void setParent(ApplicationContext parent) {
    this.parent = parent;
    if (parent != null) {
        Environment parentEnvironment = parent.getEnvironment();
        if (parentEnvironment instanceof ConfigurableEnvironment) {
            getEnvironment().merge((ConfigurableEnvironment)
parentEnvironment);
        }
    }
}

All the extant ApplicationContexts impls extend AbstractApplicationContext.

All the extant Environment impls are also ConfigurableEnvironment, so
the merge() happens.

>From its Javadoc, the merge() amongst other things merges the
PropertySource instances from the parent into the child's Environment
(unless ones with the same name already exist in the child, in which
case that child property source instance is preserved). 

Only potential issue I see is that if the parent Environment changes
*after* setParent is called on the child, it won't pick up those changes:

 Note that any changes to
 the parent environment occurring after the call to {@code merge} will
not be
 reflected in the child. Therefore, care should be taken to configure parent
 property sources and profile information prior to calling {@code merge}.


But I doubt that's an issue here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20140508/93b7233a/attachment.html 


More information about the dev mailing list