Last active
December 31, 2015 20:09
-
-
Save iesen/8038305 to your computer and use it in GitHub Desktop.
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 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