Spring cloud Spring云配置服务器-如何添加在EnvironmentEncryptorEnvironmentRepository的findOne()方法中可见的自定义PropertySource

Spring cloud Spring云配置服务器-如何添加在EnvironmentEncryptorEnvironmentRepository的findOne()方法中可见的自定义PropertySource,spring-cloud,spring-cloud-config,Spring Cloud,Spring Cloud Config,我的目标是将自定义PropertySource添加到spring云服务器。我想要实现的是在SpringCloudConfig客户端应用程序中从该自定义源获取一些自定义属性 根据我的建议,我创建了springcloudconfig服务器应用程序和单独的项目springcloudconfig自定义。第二个是基于代码的。因此,我创建了所有必要的类,如CustomPropertySource,CustomPropertySourceLocator,CustomConfigBootstrapConfigu

我的目标是将自定义PropertySource添加到spring云服务器。我想要实现的是在SpringCloudConfig客户端应用程序中从该自定义源获取一些自定义属性

根据我的建议,我创建了
springcloudconfig服务器
应用程序和单独的项目
springcloudconfig自定义
。第二个是基于代码的。因此,我创建了所有必要的类,如
CustomPropertySource
CustomPropertySourceLocator
CustomConfigBootstrapConfiguration
等等,并在
spring.Factorys
中对它们进行了配置

最后,我在我的
springcloudconfig服务器
中添加了maven依赖项到
springcloudconfig custom

到目前为止还不错。一切正常。当我启动服务器时,我可以看到我的
CustomPropertySource
EnvironmentRepository
bean注入到
EnvironmentController
中的属性资源列表上

问题:当我将GET请求发送到
@RequestMapping(“/{name}/{profiles}/{label:.*}”)
(在
EnvironmentController
中)时,注入的
environmentrepository
bean被用来查找请求的属性源(
repository.findOne(名称、配置文件、标签)
方法)。 不幸的是,在这里找不到我的财产来源。为什么?

我花了很多时间调试这个。我发现存储库将
findOne()
方法调用委托给其他存储库:
multiplejitenvironmentrepository
,它将它委托给
NativeEnvironmentRepository
。在该委托内部,findOne()方法不使用从
EnvironmentRepository
primary注入控制器的propertySources。它使用新的属性资源列表和新的独立SpringApplication创建新的环境存储库。最后,此列表不包含我的
CustomPropertySource
,这就是为什么
findOne()
在生成的
Environment
对象中返回空的propertySources的原因

  • 我做错什么了吗
  • CustomPropertySourceLocator
    (和/或
    ConsultPropertySourcelocator
    )是否应该在
    spring云配置服务器
    spring云配置客户端
    中使用(自动连接/引导)
  • spring cloud config server能否通过REST接口同时提供多种不同类型的
    属性资源(我说的“不同”是指所有Git、Concur和Zookeeper)

  • 您所做的是将属性源添加到配置服务器本身,而不是它所服务的配置。将
    spring boot starter actuator
    添加到配置服务器并查看
    /env
    将显示:

    {
      "profiles": [
    
      ],
      "server.ports": {
        "local.server.port": 8888
      },
      "bootstrapProperties:custom": {
        "test.prop3": "CUSTOM-VALUE-3",
        "test.prop2": "CUSTOM-VALUE-2",
        "test.prop1": "CUSTOM-VALUE-1"
      },
    }
    
    要添加将由config server提供服务的内容,您必须实现一个
    环境存储库


    对复合
    EnvironmentRepository
    was的支持。

    您使用的是哪个版本的SpringCloud?直到最近,如果上下文中有另一个
    EnvironmentRepository
    bean,则不会创建任何默认的
    EnvironmentRepository
    bean,因此我不知道在您的情况下如何创建
    multiplejitenvironmentrepository
    NativeEnvironmentRepository
    。您能否提供一个示例应用程序来演示您看到的问题?我使用的是1.1.0.RELEASE。我使用的是1.1.0.RELEASE<代码>环境存储库
    注入到
    环境控制器
    的最初是
    环境加密环境存储库
    。它将调用委托给
    MultipleJGitEnvironmentRepository
    ,该库继承了
    AbstractSCmenEnvironmentRepository
    的实现。最后一个文件中的FindOne()创建新的
    NativeEnvironmentRepository
    传递
    ConfigurableEnvironment
    ,其中包含我的
    CustomPropertySource
    内部的
    bootstrapproperty
    属性源。由于getArgs()方法中的“硬编码”-spring.cloud.bootstrap.enabled=false”,因此
    NativeEnvironmentRepository
    会对其进行过滤。同样,一些重现问题的代码会有所帮助。我已经准备了示例性应用程序,并使它们可用。请比较服务器端和客户端调用/myenv上下文的结果(http:/localhost:8888/myenv和)。我的自定义属性源(“自定义”)在客户端不可用。请注意,客户端不直接使用my CustomPropertySourceLocator。我试图强迫服务器为CustomPropertySourceYes服务,这就是我最终所做的。我已经实现了EnvironmentRepository,它运行良好。一开始,我确信在服务器端定义的
    bootstrapproperty
    应该可以为配置客户端自动访问。现在我明白了,我错了。所以结论是这样的:自动注册
    属性资源
    仅用于注册它的应用程序的内部使用。在我的情况下,
    config server
    可以使用我的
    CustomPropertySource
    ,但不能发布它。所以,据我所知,没有正式的方法使config server为其引导
    PropertySources
    服务。