Why? The problem is already solved. In web enviroment, use an ApplicationContextInitializer to add a PropertySource to Environment
Code:
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>com.bank.MyInitializer</param-value>
</context-param>
public class MyInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
public void initialize(ConfigurableWebApplicationContext ctx) {
PropertySource ps = new MyPropertySource();
ctx.getEnvironment().getPropertySources().addFirst(ps);
// perform any other initialization of the context ...
}
}
On other scenarios simply use the same code after context creation:
Code:
ApplicationContext ctx = new ClassPathXmlApplicationContext(...);
Properties prop = loadProperties();
PropertySource ps = PropertiesPropertySource("init_properties", prop);
ctx.getEnvironment().getPropertySources().addFirst(ps);
...
Cheers