1
votes

I would like to know if anyone has any experience or suggestions for configuring Spring Boot using remote properties (e.g., properties located in a database on a remote machine instead of an application.properties file). I am aware of Spring Boot's external config options, but these all assume configuration is done through a .properties file.

Ideally I would only have to hard-code the configuration for a single datasource, and then all subsequent configurations for the various @Beans could be done with remotely-fetched values.

Is this possible?

1

1 Answers

2
votes

Spring Cloud has a bootstrap ApplicationContext that you can customize and use to add properties to the Environment. The spring-cloud-config-client is pretty lightweight and has no mandatory dependencies other than Spring. Documentation is here. Example bootstrap configuration:

@Configuration
public class CustomPropertySourceLocator implements PropertySourceLocator {

    @Override
    public PropertySource<?> locate(Environment environment) {
        return new MapPropertySource("databaseProperties",
                getPropertiesFromDatabase());
    }

}

Implementation of getPropertiesFromDatabase() is up to you.