title: Set Spring Boot application.properties based on Environment Variable
body: <p>I have a Spring Boot application that will run in various environments, and based on the environment it runs in, it will connect to a different database. I have a few <code>application.properties</code> files, one for each environment which look like such:</p>
  
  <p><code>application-local.properties</code>:</p>
  
  <pre><code>spring.datasource.platform=postgres
  spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
  spring.datasource.username=dbuser
  spring.datasource.password=123456789
  </code></pre>
  
  <p><code>application-someserver.properties</code>:</p>
  
  <pre><code>spring.datasource.platform=postgres
  spring.datasource.url=jdbc:postgresql://someserver:5432/myproddb
  spring.datasource.username=produser
  spring.datasource.password=productionpass
  </code></pre>
  
  <p>etc. etc.</p>
  
  <p>On each of my environments, I have a environment variable called <code>MYENV</code> which is set to the type of environment it is, for example <code>local</code> or <code>someserver</code> (the name of the <code>application-{env}.properties</code> files perfectly matches the environment name). </p>
  
  <p>How can I get spring boot to read this environment variable and automatically choose the correct <code>.properties</code> file? I don't want to have to do the whole <code>-Dspring.profiles.active=someserver</code> because of the way this package is deployed (it will not be running as a jar). </p>