Last active
August 29, 2015 14:16
-
-
Save ldziedziul/d492a1e417e58d703b40 to your computer and use it in GitHub Desktop.
Multiple wars of Spring Boot app on the single Tomcat instance
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
| /* | |
| * AppWebXml.java | |
| * | |
| */ | |
| package pl.dziedziul; | |
| import org.springframework.boot.builder.SpringApplicationBuilder; | |
| import org.springframework.boot.context.web.SpringBootServletInitializer; | |
| import pl.dziedziul.app.web.Application; | |
| public class AppWebXml extends SpringBootServletInitializer { | |
| @Override | |
| protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | |
| final SpringApplicationBuilder applicationBuilder = application.sources(Application.class); | |
| String applicationName = extractContextName(application); | |
| //app will load properties from /home/tomcat/conf/<context-path>.properties | |
| applicationBuilder.properties("spring.config.name:"+applicationName); | |
| return applicationBuilder; | |
| } | |
| private String extractContextName(SpringApplicationBuilder application) { | |
| String contextName = ((WebappClassLoader) application.application().getClassLoader()).getContextName(); | |
| if (!StringUtils.isEmpty(contextName)){ | |
| contextName = contextName.substring(1); | |
| } else { | |
| throw new RuntimeException("Cannot get context name of webapp"); | |
| } | |
| return contextName; | |
| } | |
| } |
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
| #mind the slash at the end. | |
| export CATALINA_OPTS="-Dspring.config.location=file:/home/tomcat/conf/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment