簡體   English   中英

spring-cloud-config:配置文件無法正常工作

[英]spring-cloud-config: profile does not work properly

我正在學習spring-cloud-config並且我想使用不同的配置文件,但我總是從default配置文件中取回值。

我在 git 存儲庫中有兩個屬性文件,帶有prod后綴的文件覆蓋了default配置文件中的一個鍵:

  • 圖像服務.properties
  • image-service-prod.properties

看來我的配置服務器工作正常:

獲取http://localhost:8888/image-service/default

{"name":"image-service","profiles":["default"],"label":null,"version":"fb78fe4429a33c266d6eb07a9e482b8fd264dd7c","state":null,"propertySources":
[{"name":"https://bitbucket.org/.../...-configuration.git/image-service.properties","source":{"service.image.hello":"image-common"}}]}

獲取http://localhost:8888/image-service/prod

{"name":"image-service","profiles":["prod"],"label":null,"version":"fb78fe4429a33c266d6eb07a9e482b8fd264dd7c","state":null,"propertySources":
[{"name":"https://bitbucket.org/.../...-configuration.git/image-service-prod.properties","source":{"service.image.hello":"image-prod"}},
{"name":"https://bitbucket.org/.../...-configuration.git/image-service.properties","source":{"service.image.hello":"image-common"}}]}

我在 REST 應用程序中激活了prod配置文件,但始終顯示默認配置文件中的值。

客戶端應用程序的 application.properties:

server.port=8889
spring.application.name=image-service

spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=prod

客戶端應用程序的 REST 控制器:

@RefreshScope
@RestController
public class EchoController {

    @Value("${service.image.hello}")
    private String hello;

    @RequestMapping("/show")
    @ResponseBody
    public String showConfig() {
        return new StringBuilder()
                .append("image-service: ").append(hello)
                .toString();
    }
}

結果:

image-service: image-common

從客戶端應用程序登錄:

c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=image-service, profiles=[default], label=null, version=fb78fe4429a33c266d6eb07a9e482b8fd264dd7c, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://bitbucket.org/.../...-configuration.git/image-service.properties'}]}
c.r.d.springconfig.client.Application    : The following profiles are active: prod
ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7ccdc9e7: startup date [Sun Sep 23 22:31:55 CEST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@7fd618b5
o.s.cloud.context.scope.GenericScope     : BeanFactory id=51790958-c0a2-3d61-91d6-a8dcd5395c7e
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$bf37cae6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8889 (http)

似乎我錯過了一些東西,但我看不到什么。

我也在做同樣的事情,並且對如何在 spring cloud config 服務器配置中傳遞版本有疑問

我知道我們可以通過 REST 端點訪問

https://{domain}/v1/secret/data/myapp/dev?version=2

想知道如何在 Spring Cloud 配置服務器 + 客戶端實現中進行配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM