Hi Everyone,
Ran into an issue at work today and I would like some opinions/help dealing with it.
so I have an application.properties file which basically contains
spring.profiles.active=***
where the asterixis are you basically define which profile you would like to use ie dev, uat, pre-prod, prod.
So when devs are working on there local machine they use the dev
profile but sometimes forget to change this back when committing meaning that things point at the wrong place or use wrong logins etc... I originally thought I could just add application.properties to my .gitignore
file and the remote version would stay correct on github and then devs would just create a application.properties locally and specify which profile to use. Turns out this didn't work and git just will not ignore the file without removing the remote ones too.
So does anybody have any recommendations? Any help would be much appreciated
Discussion (8)
Never define your Spring profiles in
application.properties
.Pass them as a CLI parameter via
-Dspring.profiles.active=***
, with empty as the default (dev) profileI agree with Matteo when running the app in a dev environment, just add the
--spring.profiles.active=x
to the run configuration/arguments in your IDE.For deploying on a server, whether its a test server or production, you could also include an external application.properties file next to your .jar/.war archive with the specified profile and your spring app will read it and override any clashing internally defined properties.
Whether you are using ant/maven/gradle as your build tool you can usually configure a target that will output your archive with the external configuration file specifying the profile for the environment you need.
The way we usually go with Spring Boot is having a different
application.yml
(but it's the same with.properties
) for every environment and switch them by passing the CLI parameter or via theSPRING_PROFILES_ACTIVE
environment variable (very useful for containers).So we have normally four files:
application.yml
: base common configurationapplication-dev.yml
: local dev configuration, not committed to git and customized by every devapplication-test.yml
: test server configurationapplication-prod.yml
: production server configurationOptionally we could have more for specific use cases (e.g. in a project we have an
application-openshift.yml
for deploy on our Red Hat OpenShift PaaS).Thanks for the information guys, seems like passing them as a CLI parameter will be the best option for us!
Hi !
Did you find a way to solve your problem ?
We have multiple
*.properties
files, one per environment (local, dev, ...).Our
local.properties
file is tracked by Git.Since every developper adjusts the
local.properties
file to his environment the changes appear in the Working directory.I am also looking for a clean way to avoid committing my local config files and .gitignoring them is not an option.
I would appreciate any clue 😄
Thx !
Don't worry we play nice here :)
I'd recommend a #help tag instead of a #discuss tag!
How do you start up your spring (boot?) app in development? Via CLI, via your IDE, ...?