Spring Cloud Config Server 配置总结

Spring Cloud Config Server 配置总结

Spring Cloud 微服务使用配置仓库进行配置管理的时候,需要注意一些东西,自己走了一些弯路,不断去修改配置调试程序总结了一点经验,在这里记录一下。

只要依赖Config Server的应用必须在bootstrap.yml里配置相关配置仓库的信息
本人习惯使用yml配置文件,当然也可使用properties

config server 的配置(application.yml或bootstrap.yml)

server:
  port: 7003
spring:
  application:
    name: config-center
  cloud:
    config:
      server:
        git:
          uri: {https://xxxxx/config.git}
          search-paths: config-repo
          username: {username}
          password: {password}
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:7000/eureka/
#对称加密秘钥
#该配置也可放到环境变量 ENCRYPT_KEY
#使用到数据源的密码spring.datasource.password={cipher}[加密内容]
#使用前提,需要JCE包,去oracle下载,将下载来的文件解压,
#将local_policy.jar和US_export_policy.jar文件复制到jre/lib/security目录下
encrypt:
  key: {encryptKey}
#连接到配置中心的客户端进行安全验证
security:
  user:
    name: {name}
    password: {password}

app-name 的配置(依赖配置中心的配置文件名必须是bootstrap.yml)

spring:
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-center
      profile: default
      #Config Server 宕机后快速反应和重试
      fail-fast: true
      retry:
        # 初始重试间隔时间(单位毫秒)默认1000
        multiplier: 1000
        # 最大重试次数 默认6次
        max-attempts: 6
      #安全验证
      username: {username}
      password: {password}
  application:
    name: app-name
#注册中心
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:7000/eureka/

bootstrap.yml 与 application.yml

引用自stackoverflow

bootstrap.yml is loaded before application.yml.

It is typically used for the following:

  • when using Spring Cloud Config Server, you should specify spring.application.name and spring.cloud.config.server.git.uri inside bootstrap.yml
  • some encryption/decryption information
    Technically, bootstrap.yml is loaded by a parent Spring ApplicationContext. That parent ApplicationContext is loaded before the one that uses application.yml.

个人补充,如果配置是服务模式,也就是配置中心 (Config Server) 也注册到Eureka,那么eureka.client.serviceUrl. defaultZone 也应该配置到客户端的 bootstrap.yml 里,这样客户端才能发现(Discover) 配置中心

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

撸码猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值