Spring Cloud Config复合存储库

时间:2018-06-27 13:12:05

标签: spring-cloud-config

我试图配置Spring Cloud配置服务器以使用复合配置,但出现了一个奇怪的错误。 我在做什么错了?

1。原生个人资料

  

application.properties

server.port=8888    
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=file:///C:/tmp/config-repo

http://localhost:8888/app1/dev/->获得了已加载的属性

2。复合资料(本机+自定义)

  

application.properties

server.port=8888
spring.profiles.active=composite
spring.cloud.config.server.native.search-locations=file:///C:/tmp/config-repo
spring.cloud.config.server.plugins.search-locations=file:///C:/tmp/plugins-repo

错误: org.springframework.beans.factory.BeanCreationException:创建名称为“ org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration”的bean时出错:通过构造函数实例化Bean失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.act.ate.autoconfigure.EndpointAutoConfiguration $$ EnhancerBySpringCGLIB $ 271d7a4d]:构造方法抛出异常;嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源[org / springframework / cloud / config / server / config / EnvironmentRepositoryConfiguration.class]中创建名称为“ configServerHealthIndicator”的bean时出错:通过方法“ configServerHealthIndicator'参数0;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ org.springframework.cloud.config.server.config.CompositeConfiguration”的bean时出错:通过方法“ setEnvironmentRepos”参数0表示的依赖关系未满足;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org / springframework / cloud / config / server / config / DefaultRepositoryConfiguration.class]中定义的名称为'defaultEnvironmentRepository'的bean时出错:调用init方法失败;嵌套异常是java.lang.IllegalStateException:您需要为git存储库配置uri

PluginsEnvironmentRepository返回一个Environment,该Environment充满了在配置文件夹中存在的每个属性文件中找到的所有属性。 此类仅是示例,因此我不会在application / profile / label参数上实现任何过滤器。

@ConfigurationProperties("spring.cloud.config.server.plugins")
public class PluginsEnvironmentRepository implements EnvironmentRepository, Ordered {
    private int order = Ordered.LOWEST_PRECEDENCE;
    private String searchLocations;

    @Override
    public Environment findOne(String application, String profile, String label) {

        String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
        Environment env = new Environment(application, profiles, label, null, null);

        String[] locations = StringUtils.commaDelimitedListToStringArray(searchLocations);
        for (String location : locations) {
            File f = new File(URI.create(location));
            if (f.exists() && f.isDirectory()) {
                File[] propFiles = f.listFiles(new FileFilter() {

                    @Override
                    public boolean accept(File pathname) {
                        return pathname.getName().endsWith(".properties");
                    }
                });

                for (File propFile : propFiles) {
                    env.add(new PropertySource(propFile.getName(), loadProperties(propFile)));
                }
            }
        }

        return env;
    }

    private Map<String, String> loadProperties(File f) {
        ....
    }

    @Override
    public int getOrder() {
        return order;
    }

    public String getSearchLocations() {
        return searchLocations;
    }

    public void setSearchLocations(String searchLocations) {
        this.searchLocations = searchLocations;
    }

}   
  

Spring Cloud版本:Edgware.SR2

     

Spring Boot版本:1.5.10.RELEASE

0 个答案:

没有答案