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