I'll answer my own question
I created this class
Code:
public class SpringContextInitializer implements
ApplicationContextInitializer<ConfigurableWebApplicationContext> {
public void initialize(ConfigurableWebApplicationContext applicationContext) {
MyPropertySource ps = new MyPropertySource();
applicationContext.getEnvironment().getPropertySources().addFirst(ps);
}
}
You can do addLast() instead if you prefer system and env to take precedence.
in web.xml I added
Code:
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>com.example.SpringContextInitializer</param-value>
</context-param>
in my beans declaration file add
Code:
<context:property-placeholder ignore-unresolvable="true" />
The ApplicationContextInitializer is what is necessary to have this work for <import /> references. If you don't need that and your properties are in a standard properties file you don't need to do all this, you'll find easier examples elsewhere. If you leave out the last step this will only work for <import /> and all other placeholders will be ignored.
ignore-unresolvable="true" prevents errors when you can't find the placeholder (which may or may not be what you want).