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 application.properties
files, one for each environment which look like such:
application-local.properties
:
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=dbuser
spring.datasource.password=123456789
application-someserver.properties
:
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://someserver:5432/myproddb
spring.datasource.username=produser
spring.datasource.password=productionpass
etc. etc.
On each of my environments, I have a environment variable called MYENV
which is set to the type of environment it is, for example local
or someserver
(the name of the application-{env}.properties
files perfectly matches the environment name).
How can I get spring boot to read this environment variable and automatically choose the correct .properties
file? I don't want to have to do the whole -Dspring.profiles.active=someserver
because of the way this package is deployed (it will not be running as a jar).