Created
October 31, 2012 21:17
-
-
Save rponte/3989915 to your computer and use it in GitHub Desktop.
Configuring an ApplicationContextInitializer on Spring 3.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyAppCtxInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | |
private static Logger LOG = LoggerFactory.getLogger(MyAppCtxInitializer.class); | |
@Override | |
public void initialize(ConfigurableApplicationContext applicationContext) { | |
ConfigurableEnvironment environment = applicationContext.getEnvironment(); | |
try { | |
environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:env.properties")); | |
LOG.info("env.properties loaded"); | |
} catch (IOException e) { | |
// it's ok if the file is not there. we will just log that info. | |
LOG.info("didn't find env.properties in classpath so not loading it in the AppContextInitialized"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app ...> | |
<context-param> | |
<param-name>contextInitializerClasses</param-name> | |
<param-value>somepackage.MyAppCtxInitializer</param-value> | |
</context-param> | |
<listener> | |
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | |
</listener> | |
</web-app> |
This was helpful for me to get PropertySource loaded that will dynamically load in others.
I hope this would be helpful too, i have made these changes in my project.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://scottfrederick.blogspot.com.br/2012/05/custom-property-source-in-spring-31.html