spring cloud 配置中心 config 搭建过程

1.搭建config-server 服务端

1.1. 新建boot工程 pom引入依赖

<!-- config配置中心 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- eureka客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

1.2.启动类添加注解@EnableConfigServer

@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigServerApplication { public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
} }

1.3 application.properties添加配置

server.port=9003
spring.application.name=config-server #eureka注册中心
eureka.client.service-url.defaultZone=http://localhost:9001/eureka/
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port} #本地配置
#spring.profiles.active=native
#spring.cloud.config.server.native.search-locations=classpath:/ #远端配置
spring.cloud.config.server.git.uri=http://127.0.0.1:8040/root/config-resp.git
spring.cloud.config.server.git.username=root
spring.cloud.config.server.git.password=123456
spring.cloud.config.server.git.search-paths=user_service,product_service
spring.cloud.config.label=master

1.4 配置验证

远端仓库配置文件

页面读取查看

2.配置读取客户端

2.1 pom引入依赖

  <!--配置中心 客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>

2.2 添加bootstrap.properties 配置文件

由于spring boot 配置读取顺序,将config相关配置写在application.properties 无效,spring boot 会自动连接默认的localhost:8888 读取配置中心 。所以新建bootstrap.properties配置,bootstrap.properties的优先级大于application.properties。

bootstrap.properties

#eureka注册中心
eureka.client.service-url.defaultZone=http://localhost:9001/eureka/
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
#config server
spring.cloud.config.name=product_service
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server

2.3 读取配置,使用验证

程序代码

@Value("${product.name}")
private String productName; @GetMapping("/getProductName")
public String getProductName(){
return productName;
}

调用程序获取

项目github 地址  https://github.com/yongxiangliu123/SpringCloud

spring cloud(三) config的更多相关文章

  1. Alibaba Nacos 学习(二):Spring Cloud Nacos Config

    Alibaba Nacos 学习(一):Nacos介绍与安装 Alibaba Nacos 学习(二):Spring Cloud Nacos Config Alibaba Nacos 学习(三):Spr ...

  2. Spring Cloud Consul Config 知识点

    Spring Cloud Consul Config 是 Config Server 和 Client的替代方案. 搭建一个配置中心,可以选择的方案: Spring Cloud Config 或者 S ...

  3. Spring Cloud之——Config(配置中心)

    Spring Cloud Config(配置中心) 大家好,有一段时间没有写技术博客了.由于工作上的事情,这方面很难分配时间.近几年随着服务化的兴起,一批服务化的框架应运而生,像dubbo,thrif ...

  4. Spring Cloud(四) --- config

    Spring Cloud Config 随着线上项目变的日益庞大,每个项目都散落着各种配置文件,如果采用分布式的开发模式,需要的配置文件随着服务增加而不断增多.某一个基础服务信息变更,都会引起一系列的 ...

  5. Spring Cloud 之 Config与动态路由.

    一.简介  Spring Cloud Confg 是用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,它分为服务端与客户端两个部分.其中服务端也称为分布式配置中心,它是一个独立的微服务 ...

  6. spring cloud(三)服务提供与调用

    服务提供 我们假设服务提供者有一个hello方法,可以根据传入的参数,提供输出“hello xxx,this is first messge”的服务 1.pom包配置 创建一个springboot项目 ...

  7. Spring Cloud(三):服务提供与调用

    上一篇文章我们介绍了eureka服务注册中心的搭建,这篇文章介绍一下如何使用eureka服务注册中心,搭建一个简单的服务端注册服务,客户端去调用服务使用的案例. 案例中有三个角色:服务注册中心.服务提 ...

  8. spring cloud (八) Config client 和项目公共配置

    1 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

  9. spring cloud (七) Config server基于svn配置

    1 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

随机推荐

  1. AtCoder ABC 076D - AtCoder Express

    传送门:http://abc076.contest.atcoder.jp/tasks/abc076_d 本题是一个运动学问题——匀变速运动. 一个质点,从静止开始运动.按照速度限制,可将运动划分成n个 ...

  2. 【ACM】poj_2210_Metric Time_201308011933

    Metric TimeTime Limit: 1000MS  Memory Limit: 65536K Total Submissions: 2550  Accepted: 783 Descripti ...

  3. 【ACM】hdu_1095_A+BVII_201307261740

    A+B for Input-Output Practice (VII)Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  4. 洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails(不明原因的scanf错误)

    P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总 ...

  5. Sublime Text 3常用插件—Emmet

    原文链接:http://www.cnblogs.com/easy-blue/p/6617852.html 摘要: 安装请看上一篇Sublime Text—安装,和sublime自带快捷键一起用,写ht ...

  6. centos 解压压缩包到指定目录

    解压.tar.gz文件: tar -zxvf web.tar.gz tar不支付解压文件到指定的目录! 解压.war .zip文件到指定目录: unzip web.war -d webapps/ROO ...

  7. unity游戏开发之NGUI的UISprite染色

    游戏的UI开发中常常会遇到染色问题.比如button失效变灰的效果,同一个道具通过策划表配的颜色值染上红绿蓝紫等颜色,效果例如以下 最笨最挫的方法当然是让美术多出几个资源图.这种一个缺点是浪费资源,在 ...

  8. vmware mac 分辨率设置

    1.安装vmware tool 2.关闭虚拟机,在设置中找到显示器项 3.选中“加速3D图形” 4.在监视器中,选中 指定监视器设置,使用任意分辨率 5.如果没有可用分辨率,手动输入,例如 1680* ...

  9. python:sql建表语句转换为json

    第一种sql格式: CREATE TABLE prpcitem_car ( proposalno ) NOT NULL, itemno ,) NOT NULL, riskcode ) NOT NULL ...

  10. vue组件的3种书写形式

    第一种使用script标签 <!DOCTYPE html> <html> <body> <div id="app"> <my- ...