问题
I'm fairly new to Spring Boot so please excuse me if I'm overlooking something simple.
With the Spring Config Server, you are able to specify via .yml files what type of environment repository that you would like to use (native, Git, etc). These environment repositories are included in the third-party dependency. I was wondering if it was possible to add your own environment repository so you can, for example, connect to a database to pick up configuration?
Many thanks in advance!
回答1:
you certainly can. See spring cloud consul config as an example. The guts is a PropertySource
public class MyPropertySource extends EnumerablePropertySource<MyClient> {
@Override
public Object getProperty(String name) {
return /* your impl */;
}
@Override
public String[] getPropertyNames() {
return /* your impl here */;
}
}
You also need a PropertySourceLocator, a bootstrap configuration and a META-INF/spring.factories that points to the bootstrap config`.
回答2:
As spencergibb stated in another thread, a PropertySource only provides configuration for the config server itself and is not accessible for the spring boot config clients.
What you actually need is an implementation of the EnvironmentRepository interface. I provided an example for a simple CustomEnvironmentRepository in Spring Boot Config custom environment repository
来源:https://stackoverflow.com/questions/29120491/adding-environment-repository-in-spring-config-server