Skip to content

Instantly share code, notes, and snippets.

@iesen
Last active December 31, 2015 20:09
Show Gist options
  • Save iesen/8038305 to your computer and use it in GitHub Desktop.
Save iesen/8038305 to your computer and use it in GitHub Desktop.
public class WebAppInitializer implements WebApplicationInitializer {
private static final Logger logger = LoggerFactory.getLogger(WebAppInitializer.class);
public static final String PROFILE_CONFIG_FILE = "/config/profile.config";
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
try {
// Access profile config file for active profile
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream(PROFILE_CONFIG_FILE));
// Activating profile obtained from profile config file
String profile = properties.getProperty("spring.profiles.active");
servletContext.setInitParameter("spring.profiles.active", profile);
// Creating spring application context with AppConfig class
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(AppConfig.class);
servletContext.addListener(new ContextLoaderListener(applicationContext));
} catch (IOException e) {
logger.error("Profile activator config file not found: {}", PROFILE_CONFIG_FILE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment