Spring   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么spring客户端无法获取spring配置服务器属性?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个运行生产配置文件的@SpringBootApplication和一个spring配置服务器,

{"name":"config-client","profiles":["production"],"label":null,"version":"97611975e6ddb87c7213e18ddbe203ab6ae5485d","state":null,"propertysources":[{"name":"http://git/scm/abm/abm-setTings.git/application-production.yml","source":{"my.pretty.property.id":21}}]}

我无法从服务器加载@L_463_6@my.pretty.property.id(它们总是为null),我正在使用

@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "my.pretty.property")
public class MyProperties {
    private String id;
}

和我的bootstrap.yml是

spring.cloud:
  config:
    uri: http://${serviCE_HOST}/${PROjeCT_KEY}-config-server
    enabled: false
    failFast: true

build.gradle包含这个:

"org.springframework.cloud:spring-cloud-starter-consul-all","org.springframework.cloud:spring-cloud-consul-core","org.springframework.cloud:spring-cloud-starter-hyStrix","org.springframework.cloud:spring-cloud-starter-hyStrix-dashboard","org.springframework.cloud:spring-cloud-starter-zipkin","org.springframework.cloud:spring-cloud-config-client"

我的客户端应用程序通常是构建和部署的,我缺少什么?

最佳答案
Spring Cloud Config开始:

正如您所提到的,您的应用程序正在生产配置文件下运行 – 因此Spring将尝试查找文件:< cloud-config-server-url=""> /application-production.yml并加载它,除了application.properties.但是您的属性位于application-integration.yml中,并且您不使用集成配置文件.

因此,解决方案是使用集成配置文件或在配置上创建application-production.yml.服务器.

大佬总结

以上是大佬教程为你收集整理的为什么spring客户端无法获取spring配置服务器属性?全部内容,希望文章能够帮你解决为什么spring客户端无法获取spring配置服务器属性?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。