title: Spring Boot: Multiple WAR deployment in same tomcat different properties
body: <p>So I have to deploy the same springboot app as multiple apps in the same tomcat server.
  eg <code>/app1</code> <code>/app2</code> <code>/app3</code>.</p>
  <p>They share most of the same configuration except for datasource configuration.</p>
  <p>I've been searching for a way to externalise the datasource configuration based on the <code>servlet-context</code> or something like that.</p>
  <p>Using springs externalised configuration, I am able to get it to load the <strong>same</strong> external data source file for <strong>all</strong> apps, but they need to be different. eg.</p>
  <pre><code>@PropertySource(value = &quot;file:${HOME}/datasource-override.properties&quot;, ignoreResourceNotFound=false)
  </code></pre>
  <p>Using the embedded tomcat mode, ie via say <code>.\gradlew bootRun</code> I think I can achieve it.
  I just need to use the following as the application.properties for that profile sets the <code>server.context-path</code> property. (as this is a single app) eg.</p>
  <pre class="lang-java prettyprint-override"><code>@PropertySource(value = &quot;file:${HOME}/${server.context-path}/datasource-override.properties&quot;, ignoreResourceNotFound=false),
  </code></pre>
  <p>Searching around, I thought it might be something like (and combinations of) the following, but it didn't work. eg</p>
  <pre><code>@PropertySource(value = &quot;file:${HOME}/${server.servlet.context-path}/datasource-override.properties&quot;, ignoreResourceNotFound=false)
  </code></pre>
  <p>All examples I've found so far deal with either the embedded tomcat, or a single externalised property file for a single app.</p>
  <p>Ideally I would like it to find the file in either it's own directory</p>
  <pre class="lang-java prettyprint-override"><code>file:${HOME}/${server.servlet.context-path}/datasource.properties
  </code></pre>
  <p>So for the three apps it would be something like the following, where it detects from it's deployed context, what the location for it's property file is. eg:</p>
  <pre class="lang-java prettyprint-override"><code>file:${HOME}/app1/datasource.properties
  file:${HOME}/app2/datasource.properties
  file:${HOME}/app3/datasource.properties
  </code></pre>
  <p>Obviously if the app was deployed as <code>/funky_chicken</code> then it would have a matching <code>funky_chicken/datasource.properties</code></p>
  <p>Any thoughts ? I know I am probably close, and I've tried dumping all the environmental properties. (you are probably are going to tell me to get it from <code>JNDI</code> as it's the only one I haven't dumped looking for the context)</p>
  <p>Now I know <code>${HOME}</code> is not the best place to store config items, it really is just to make it easier to describe the issue.</p>
  <p>Update:</p>
  <p>Thanks to the suggestions to use profiles, is there a way to have three active profiles in the one tomcat server, <code>/app1</code>, <code>/app2</code> and <code>/app3</code> from the same <code>WAR</code> file?</p>