-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Description
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
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug