Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Spring Cloud Config with local GIT repo instead of GitHub?

Tags:

spring-cloud

Has anyone configured Spring Cloud Config to use a local GIT repo instead of GitHub? If so could you share your config?

like image 970
Brian Abston Avatar asked Nov 14 '14 21:11

Brian Abston


2 Answers

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
like image 130
spencergibb Avatar answered Nov 09 '22 12:11

spencergibb


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);
like image 29
ksevindik Avatar answered Nov 09 '22 12:11

ksevindik