Reputation: 6990
I have a Spring Boot application which uses the default application.yml to define configuration properties. At the moment, this file has some environment specific information such as SMTP server details, which I would like to externalize to a database table. I tried to modify this example given for a traditional Spring application here http://www.javacodegeeks.com/2012/11/spring-3-1-loading-properties-for-xml-configuration-from-database.html but so far no luck.
What is the best approach for doing this with Spring Boot?
Upvotes: 3
Views: 2914
Reputation: 606
The approach recommended by Spring Boot, and deployment platforms like Heroku is to provide overrides specific to environment as linux environment variables.
One downside of storing them in the database, is that if you ever backup your production database and restore it to some other environment, it will try to connect to your production mail server / database, etc...
With Spring Boot, any property can be overriden by environment variables.
One other thing I did myself, which I am quite happy with, is I set some of my properties to a special value, like "MUST_PASS_IN" or something like that, and at startup, I do a loop over all the properties and if any of them has that value, I stop the application and print it out. That way I guarantee that I won't forget to pass in some override in an environment.
Upvotes: 2