加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

为什么spring客户端无法获取spring配置服务器属性?

发布时间:2020-12-15 01:44:45 所属栏目:大数据 来源:网络整理
导读:我有一个运行生产配置文件的@SpringBootApplication和一个spring配置服务器, {"name":"config-client","profiles":["production"],"label":null,"version":"97611975e6ddb87c7213e18ddbe203ab6ae5485d","state":null,"propertySources":[{"name":"http://git

我有一个运行生产配置文件的@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}}]}

我无法从服务器加载属性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开始:

The HTTP service has resources in the form:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读