Has anyone configured Spring Cloud Config to use a local GIT repo instead of GitHub? If so could you share your config?
The Spring Cloud Config server tests do this.
The uri ends up looking like this file:./target/test-classes/config-repo/
You can do something like this in bootstrap.properties
spring.cloud.config.server.git.uri=file:/path/to/your/git/repo
As of spring-cloud-config-montior 2.0.0.RELEASE, FileMonitorConfiguration discards monitoring changes on local git repository paths unless they are resolved as FileSystemResource. Unfortunately, ApplicationContext DefaultResourceResolver returns FileUrlResource instead of FileSystemResource if local git repo path is given like file:/path/to/your/git/repo/. My workaround is to create a custom ProtocolResolver, which is SPI for extending DefaultResourceLoader, and utilize FileSystemResourceLoader to return FileSystemResource if local git repo path starts with '//'.
SpringApplication app = new SpringApplication(ConfigserviceApplication.class);
app.addInitializers(new ApplicationContextInitializer<ConfigurableApplicationContext>() {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ProtocolResolver resolver = new ProtocolResolver() {
private FileSystemResourceLoader resourceLoader = new FileSystemResourceLoader();
@Override
public Resource resolve(String location, ResourceLoader resourceLoader) {
if(location != null && location.startsWith("//")) {
return this.resourceLoader.getResource(location);
}
return null;
}
};
applicationContext.addProtocolResolver(resolver);
}
});
app.run(args);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With