I have a Spring Boot application with some configuration.
I want to specify different configuration values, for dev
and production
.
My application.properties
file look like this:
spring.datasource.url=jdbc:mysql://devhost:devport/devschema
spring.datasource.username=devuser
spring.datasource.password=mypwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
This file is in my git repo on Openshift. Everytime I commit, Openshift start to deploy the application, so I need the application.properties
with the correct values.
Is it possible to use something like profiles to change the configuration?
You can use the spring.profiles.active
Spring property to pick whichapplication-[environment].properties
file to use. Then create multiple files, one for each environment. To set the environment just pass this --spring.profiles.active=development
in your Java arguments.
Create different property files for different profiles using application-{profile}.properties
format, e.g. application-dev.properties
for dev
, and put your profile specific configurations in them. Then when you're running the spring boot application, activate your intended profile using the SPRING_PROFILES_ACTIVE
environment variable or spring.profiles.active
system property.
Since you're using Openshift, you can export the envirnemnt variable in the build
file in the .openshift/action_hooks
directory. Something like this:
export JAVA_OPTS_EXT=-Dspring.profiles.active="dev"
The better approach is to use rhc env set
command for enabling one specific profile:
rhc env set SPRING_PROFILES_ACTIVE=dev -a App_Name
You can read more about using environment variables in openshift here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With