简体   繁体   English

在客户端修改spring cloud config server

[英]Modify spring cloud config server in the client

I have a spring boot powered spring cloud application with a configuration server running seperately on port say 8001 on localhost.我有一个由 Spring Boot 驱动的 Spring Cloud 应用程序,其中有一个配置服务器在本地主机上的 8001 端口上单独运行。

Meanwhile, location has been specified in the config client applications/micro services as below in the bootstrap.yml file of the client project.同时,在客户端项目的 bootstrap.yml 文件中的配置客户端应用程序/微服务中指定了位置,如下所示。

spring:
  cloud:
    config:
      uri: http://localhost:8001

This works absolutely fine.这工作得很好。

However when i want to deploy the whole application on different setups, i would need to run the config server on different IPs and Ports.但是,当我想在不同的设置上部署整个应用程序时,我需要在不同的 IP 和端口上运行配置服务器。

In that case i can not go and change the IP:Port information of the config server in all the projects, rebuild the jar and deploy them.在这种情况下,我无法更改所有项目中配置服务器的 IP:Port 信息,重建 jar 并部署它们。 In fact in most scenarios, Jenkins build the Jars by itself on different environment.事实上,在大多数情况下,Jenkins 在不同的环境中自行构建 Jars。

How can we handle such situation?我们如何处理这样的情况? Can we specify an environment variable in the bootstrap.yml, if yes how to do it?我们可以在bootstrap.yml中指定一个环境变量,如果是怎么做?

Any suggestion?有什么建议吗?

Br,溴,

AJ AJ

You can definitely use environment variables in your bootstrap.yml file:您绝对可以在 bootstrap.yml 文件中使用环境变量:

spring:
  cloud:
    config:
      uri: http://${configServerHost}:${configServerPort}

When you launch your application you only have to add -DconfigServerHost=localhost -DconfigServerPort=8001启动应用程序时,只需添加-DconfigServerHost=localhost -DconfigServerPort=8001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM