SpringCloud分布式配置


最近在讲SpringCloud,下面将Spring Cloud中的分布式配置config的操作步骤记录如下:

第一步:在项目能够访问的git上新建一个工程(此处选择的gitee.com,可以选择其他的,也可以选择局域网的gitlab等),并在工程中新建文件夹,并新建对应的项目中需要使用的配置信息。(具体见https://gitee.com/migid/myconfig/)

第二步:编写config server,代码如下:

application.yml

spring:

application:

name: config_server

cloud:

config:

server:

git:

uri: https://gitee.com/migid/myconfig/

search-paths: configs

# username: 私有项目需要git的用户名

# password: 私有项目需要git的密码

label: master

server:

port: 8887

# 配置的本地配置中心

eureka:

client:

service-url:

defaultZone: http://192.168.52.44:8888/eureka/

MyconfigserverApplication.java

@EnableEurekaClient

@EnableConfigServer

@SpringBootApplication

public class MyconfigserverApplication {

public static void main(String[] args) {

SpringApplication.run(MyconfigserverApplication.class, args);

}

}

第三步:编写其他调用服务,即config-client

首先删除项目中的application.properties或yml文件。

添加bootstrap.yml文件:

spring:

application:

name: mycloudtest

cloud:

config:

label: master

profile: dev

discovery:

enabled: true

service-id: config_server

server:

port: 8982

#此处既要发现配置中心,又要在远程的配置文件中找到服务中心的地址并注册到服务中心

eureka:

client:

service-url:

defaultZone: http://192.168.52.44:8888/eureka/,${eureka_url}

剩下的代码就跟使用普通的方式继续编写就可以了,例如使用ribbon或者feign调用后端服务等。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值