Skip to content

Instantly share code, notes, and snippets.

@Cameron-C-Chapman
Last active February 23, 2016 22:49
Show Gist options
  • Save Cameron-C-Chapman/5cfed927e8958e497d95 to your computer and use it in GitHub Desktop.
Save Cameron-C-Chapman/5cfed927e8958e497d95 to your computer and use it in GitHub Desktop.
SpringBootServletInitializer to set spring profile through tomcat system argument (system property) when deploying as war
package package.name;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.apache.commons.lang.StringUtils;
// auto detected by SpringServletContainerInitializer, which itself auto detected by Servlet 3.0 container
public class WebInitializer extends SpringBootServletInitializer {
private final static Logger LOGGER = LoggerFactory.getLogger(WebInitializer.class);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
String env = System.getProperty("my.environemnt.arg");
if (StringUtils.isBlank(env)) {
env = "local";
}
LOGGER.info("ACTIVE_PROFILE={}", env);
application.profiles(env);
return application.sources(SpringBootApplicationClassName.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment