https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html
The mechanism is based on Spring boot properties
and on tomcat 7/8 configuration :
- http://stackoverflow.com/questions/15064260/should-you-set-up-database-connection-properties-in-server-xml-or-context-xml
- http://stackoverflow.com/questions/6345793/can-i-create-a-custom-classpath-on-a-per-application-basis-in-tomcat
The solution uses the $CATALINA_BASE/conf/[engine_name]/[host_name]/app.xml file which is DELETED when app.war is undeployed (so also when you update the war, redeploy, or restart the tomcat...)
make sure that you keep a copy of app.xml, or maybe in META-INF/context.xml
http://tomcat.apache.org/tomcat-6.0-doc/config/host.html#Automatic%20Application%20Deployment
demo.war
on Tomcat 8
Spring boot controller :
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyController {
@Value("${ma.variable.valeur}")
private String value;
@RequestMapping("/*")
public String getAll() {
return value;
}
}
with application.properties
ma.variable.valeur = LOL
This is the basic configuration for deploying a Spring boot app with Tomcat 8.
Tomcat 8 JVM options containing -Dspring.profiles.active=dev
/conf/Catalina/localhost/demo.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/demo">
<Resources>
<PostResources className="org.apache.catalina.webresources.DirResourceSet"
webAppMount="/WEB-INF/classes" base="/tmp/demo" />
</Resources>
</Context>
Now in /tmp/demo
, let's create application-dev.properties
:
ma.variable.valeur=OVERRIDE
The rest request should now return : OVERRIDE