spring配置中心的使用
- 配置中心原理
Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持。配置服务中心采用Git的方式存储配置文件,因此我们很容易部署修改,有助于对环境配置进行版本管理。
配置中心使用了git 管理,yml 配置文件上传到git 服务器上,便于版本管理。
开发人员直接在git 上修改。
使用方式
- *本地配置文件启用配置中心
server:
port: 8030
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8010/eureka/ #eureka服务注册地址
# git管理配置
spring:
cloud:
config:
server:
git:
uri: https://github.com/fengzp/config/ #git仓库地址
searchPaths: demo* #搜索路径
# username: username
# password: password
application:
name: config-server
2. 启动命令启用配置中心
使用命令启用配置中心
nohup java -jar /usr/local/spring-boot/service-${name}-1.0.0-SNAPSHOT.jar --logging.path=/usr/
local/spring-boot/ --spring.cloud.config.enabled=true --spring.cloud.bootstrap.name=http-remo
te-file--spring.config.location=http://10.200.141.107/bootstrap.main.yml,http://10.200.141.107
&
环境中需要有一个spring 配置中心,启动的时候配置中心地址,配置的指向配置中心,配置中心从git 上读取配置
命令启动配置中心,程序先从配置中心读取配置,如果配置失败,读取本地配置
开发过程中保证 本地配置与配置中心配置一致