繁体   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