问题描述
我想知道是否有一个示例,该示例如何为Spring Cloud Config创建自定义EnvironmentRepository,原因是存在git,svn,保管库,但是我不想使用它们,我需要我的自定义库.例如,如果我只想将所有属性存储在地图中.
I am wondering is there an example how to create a custom EnvironmentRepository for Spring Cloud Config, cause there are git, svn, vault repositories, but I don't wanna use them, I need my custom one. For instance if I just want to store all properties in a Map.
推荐答案
在您的应用程序上下文中以bean的形式提供EnvironmentRepository的实现.然后,Spring cloud config服务器将自动将其拾取.这是一个简单的示例:
Provide an implementation of the EnvironmentRepository as a bean in your application context. Spring cloud config server then will pick it up automatically.Here's a minimalistic example:
public class CustomEnvironmentRepository implements
EnvironmentRepository
{
@Override
public Environment findOne(String application, String profile, String label)
{
Environment environment = new Environment(application, profile);
final Map<String, String> properties = loadYouProperties();
environment.add(new PropertySource("mapPropertySource", properties));
return environment;
}
}
请注意,如果您有多个EnvironmentRepository(Git,Vault,Native ...),则还需要实现Ordered接口来指定订单.
Note if you have multiple EnvironmentRepository (Git, Vault, Native...) you'd also want to implement the Ordered interface to specify an order.
一种好方法是查找现有的EnvironmentRepository实现,例如07-18 02:07