Created
June 9, 2015 09:44
-
-
Save ludo1026/99a986e994068a02220d to your computer and use it in GitHub Desktop.
Spring Boot & Tomcat - War - ApplicationWebXML.java
This file contains 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 com.myimmo; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.boot.builder.SpringApplicationBuilder; | |
import org.springframework.boot.context.web.SpringBootServletInitializer; | |
import com.myimmo.config.Constants; | |
/** | |
* This is a helper Java class that provides an alternative to creating a web.xml. | |
*/ | |
public class ApplicationWebXml extends SpringBootServletInitializer { | |
private final Logger log = LoggerFactory.getLogger(ApplicationWebXml.class); | |
@Override | |
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | |
return application.profiles(addDefaultProfile()) | |
.showBanner(false) | |
.sources(Application.class); | |
} | |
/** | |
* Set a default profile if it has not been set. | |
* <p/> | |
* <p> | |
* Please use -Dspring.profiles.active=dev | |
* </p> | |
*/ | |
private String addDefaultProfile() { | |
String profile = System.getProperty("spring.profiles.active"); | |
if (profile != null) { | |
log.info("Running with Spring profile(s) : {}", profile); | |
return profile; | |
} | |
log.warn("No Spring profile configured, running with default configuration"); | |
return Constants.SPRING_PROFILE_DEVELOPMENT; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment