Adding environment repository in Spring Config Server

南笙酒味 提交于 2019-12-06 14:50:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!