您的位置:首页 > 编程语言 > Java开发

Spring Cloud Config Server 配置总结

2017-12-21 16:40 507 查看

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/[/code] 
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) 配置中心
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息