Last active
February 23, 2016 22:49
-
-
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
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
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