3

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?

2
  • Take a look at this cloud.spring.io/spring-cloud-config and github.com/spring-cloud-samples/configserver Commented May 30, 2015 at 15:10
  • I've played around with Spring Cloud earlier and I feel it's a little bit too much for the scenario I have. In this particular case, I would prefer not to run a separate service just for this, and also would like to avoid setting up Git repos for that. Another requirement I have is to let the user modify these using a UI, so I want it to be stored in the database if at all possible. Commented May 30, 2015 at 23:11

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

This approach does not address my requirement of allowing the user modify it via the UI, but I guess this is the best answer so far.
SMTP was a bad example I guess :) There are some other parameters which we want to let the administrators change through a UI, like cron expressions for some schedulers we have, tweak log levels etc.
@YohanLiyanage, you should post your answer and the way you fixed it
@FedericoPiazza We went ahead with Spring Cloud Config Server eventually. We decided that using a Git backend where the history is kept is the ideal for configuration files. Some of the other requirements for our application also changed and we had to add other Spring Cloud services as well, so Config Server became a viable solution for us.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.