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.
Asked
Active
Viewed 5,920 times
1 Answers
11
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;
}
}
Note if you have multiple EnvironmentRepository (Git, Vault, Native...) you'd also want to implement the Ordered interface to specify an order.
A good approach is to look up existing EnvironmentRepository implementation like the VaultEnvironmentRepository from the Spring cloud config server package.

Felix Oldenburg
- 223
- 3
- 7
-
1I also created a small maven lib with a ZooKeeper EnvironmentRepository to be used as a plug and play dependency for Spring Cloud Config Server. See github.com/felixoldenburg/JonesEnvironmentRepository – Felix Oldenburg Sep 17 '17 at 12:21
-
1I'm trying something similar here - but not working . See https://stackoverflow.com/questions/48762915/custom-spring-config-environmentrepository-not-being-picked-up – Vinay B Feb 13 '18 at 19:44
-
1I used a custom environment repository, but the config server no longer loads native nor git environment properties, only custom environment properties are loaded. I want load custom + native/git. Any ideas please – Komoo Apr 04 '19 at 21:36
-
2Ensure the profiles are active: SPRING_PROFILES-ACTIVE=git,keyvault – Daniel Hilgarth Jul 04 '20 at 11:14