-
-
Save hoyacom/d3d482174406b920a2e84249f3133fda 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment