Spring Loading foreign configuration from database

I have a Spring Boot application that uses default.yml to define configuration properties. At the moment this file has some environment related information such as SMTP server data, which I would like to externalize into a database table. I tried to modify this example for a traditional Spring application here http://www.javacodegeeks.com/2012/11/spring-3-1-loading-properties-for-xml-configuration-from-database.html but no luck so far ...

What's the best way to do this with Spring Boot?

+3


source to share


1 answer


The approach recommended by Spring Boot and deployment frameworks like Heroku is to provide environment specific overrides like linux environment variables.

One drawback of storing them in the database is that if you've ever backed up your production database and restored it to some other environment, it will try to connect to your production mail server / database, etc.



With Spring Boot, any property can be overridden by environment variables.

Another thing I did myself, which I'm quite happy with, is to set some of my properties to a special value, like "MUST_PASS_IN" or something like that, and on startup I loop through all properties and if any- either of them has this value, I stop the application and print it. This way I ensure I don't forget to skip over some override in the environment.

+2


source







All Articles