首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么spring客户端不能获得spring配置服务器属性?

为什么spring客户端不能获得spring配置服务器属性?
EN

Stack Overflow用户
提问于 2019-02-15 15:33:12
回答 2查看 826关注 0票数 5

我有一个@SpringBootApplication,运行着production配置文件,还有一个spring配置服务器,

代码语言:javascript
复制
{"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 (它们总是空的),我正在使用

代码语言:javascript
复制
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "my.pretty.property")
public class MyProperties {
    private String id;
}

我的bootstrap.yml是

代码语言:javascript
复制
spring.cloud:
  config:
    uri: http://${SERVICE_HOST}/${PROJECT_KEY}-config-server
    enabled: false
    failFast: true

build.gradle包含以下内容:

代码语言:javascript
复制
"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"

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-28 13:41:34

下面的配置是正确的,但是spring.cloud.config.enabled应该是正确的,我没有在我的生产环境中过度使用它

票数 0
EN

Stack Overflow用户

发布于 2019-02-19 19:16:11

来自弹簧云Config

HTTP服务具有以下形式的资源: /{应用程序}/{配置文件}/{label} /{应用程序}-{配置文件}.yml /{label}/{application}-{profile}.yml /{应用程序}-{配置文件}.properties /{label}/{application}-{profile}.properties

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

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54712485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档