微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么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}}]}

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐