I have a Spring application and I would like to be able to switch between configurations depending if I\'m debugging the server or if the server is running in production. (t
You can have 3 properties files, application-dev.properties
, application-prod.properties
and application.properties
. And you can specify all the development properties in your dev properties file and production cionfiguration properties in your prod file
and specify the profile in your application.properties
files as below
spring.profiles.active=dev
or you can select/override the profile using -Dprofile=
argument in command line.
Spring profiles seem the way to go. You can start your application with something like -Dprofile=. Have a look at this example.
EDIT: after re-reading your question, I came to the conclusion that you might actually want something more basic: put your database properties externally. Depending on your application you could use @Value of a property configurator. Have a look at the spring docs.