Externalize your configuration from war
For settings that are going to change across different environments like database connection, you should externalize them from your war file. So, you can have your war be environment agnositic. Then, you can promote via simply copying your war across different environments. In Spring, there are several ways to achieve this.
What does Spring provide?
- PropertyPlaceHolderConfigurer
- PropertyOverrideConfigurer
- Write your own ApplicationContext
The first solutions you can get the detailed from here. For the 3rd solution, you can subclass XmlWebApplicationContext and override the loadBeanDefinitions method.
public class XmlWebApplicationContext extends
org.springframework.web.context.support.XmlWebApplicationContext {
private static ApplicationContextOverride eaco = new ApplicationContextOverride();
protected final void loadBeanDefinitions(final XmlBeanDefinitionReader reader)
throws IOException {
ArrayList allLocations = new ArrayList(); // get standard locations
String[] configLocations = getConfigLocations();
allLocations.addAll(Arrays.asList(configLocations));
allLocations.addAll(eaco.findFiles(configLocations));
for (String apc : allLocations) {
log.info("loading file: " + apc);
reader.loadBeanDefinitions(apc);
}
}
}






































(4.75 out of 5)
1 Comment Received
Pingback & Trackback
Sorry the comment area are closed for non registered users