Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClasspathXmlApplicationContext does not inherit/merge parent context environment [SPR-11068] #15695

Closed
spring-issuemaster opened this issue Nov 5, 2013 · 4 comments
Assignees
Labels
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 5, 2013

Martin Gerlach opened SPR-11068 and commented

I have a root ApplicationContext with environment as follows:

StandardServletEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment,/data/myproject/conf/config.properties]}

Then, when I create a new child context as follows:

final ApplicationContext childContext = new ClassPathXmlApplicationContext(new String[] {"classpath:com/example/childcontext.xml"}, parentContext);

its environment shows as follows:

StandardEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[systemProperties,systemEnvironment]}

So, no servlet stuff, no custom properties file in the propertySources.

However, creating the child context as follows behaves different:

final GenericApplicationContext childContext = new GenericApplicationContext(parentContext);
final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(childContext);
xmlReader.loadBeanDefinitions("classpath:com/example/childcontext.xml");
childContext.refresh();

Now, the childContext's environment shows as

StandardEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[systemProperties,systemEnvironment,servletConfigInitParams,servletContextInitParams,jndiProperties,/data/myproject/conf/config.properties]}

From looking at the code, it becomes quite clear why this is: Using the given constructor of ClasspathXmlApplicationContext does not result in a call to AbstractApplicationContext.setParent(ApplicationContext parent) which would merge the environment of the parent into the own environment.


Affects: 3.2.4

Referenced from: commits 863570a, c5fcf19

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 5, 2013

Juergen Hoeller commented

Good point - fixed for 4.0 RC2 and 3.2.5 now.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 5, 2013

Martin Gerlach commented

Wow, that was pretty fast :) Thanks! I didn't check if any other ApplicationContext implementations possibly have the same issue, maybe it's worth it.
Cheers,
Martin

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 5, 2013

Juergen Hoeller commented

They all either delegate to AbstractApplicationContext's constructor with a parent argument or call setParent directly. Since this fix is actually in AbstractApplicationContext itself, we should have covered all implementations.

FYI, 3.2.5 should be available tomorrow morning :-)

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 7, 2013

Martin Gerlach commented

Works perfectly, thanks again for the quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.