Can anyone offer me some guidance on the best way for me to achieve this goal.
I'd like to extend the Spring Boot Externalized Configuration so that I have a single method which can be called from anywhere in my application. This method will retrieve a property value using a key. This method will first interrogate a database table and if it does not find the specified key it will then fall back on the PropertySource order described in 1.
So I'd have a service similar to:
@Service
public class ConfigurationService {
private final ConfigurationRepository configurationRepository;
@Autowired
public ConfigurationService(ConfigurationRepository configurationRepository) {
this.configurationRepository = configurationRepository;
}
public String getValue(String key) {
Configuration configuration = configurationRepository.findOne(key);
// Add something here to get the property from application.properties if the key does not exist in the db
return configuration == null ? null : configuration.getValue();
}
}
Which I can use as follows:
foo = configuration.getValue("my.property");
Is there a better way of going about this? Am I missing a Spring Boot feature that I could utilise?
EDIT: I'd like to be able to change the values of the properties while the application is running and have these new values picked up.
See Question&Answers more detail:os