spring cloud(三) config
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的更多相关文章
- Alibaba Nacos 学习(二):Spring Cloud Nacos Config
Alibaba Nacos 学习(一):Nacos介绍与安装 Alibaba Nacos 学习(二):Spring Cloud Nacos Config Alibaba Nacos 学习(三):Spr ...
- Spring Cloud Consul Config 知识点
Spring Cloud Consul Config 是 Config Server 和 Client的替代方案. 搭建一个配置中心,可以选择的方案: Spring Cloud Config 或者 S ...
- Spring Cloud之——Config(配置中心)
Spring Cloud Config(配置中心) 大家好,有一段时间没有写技术博客了.由于工作上的事情,这方面很难分配时间.近几年随着服务化的兴起,一批服务化的框架应运而生,像dubbo,thrif ...
- Spring Cloud(四) --- config
Spring Cloud Config 随着线上项目变的日益庞大,每个项目都散落着各种配置文件,如果采用分布式的开发模式,需要的配置文件随着服务增加而不断增多.某一个基础服务信息变更,都会引起一系列的 ...
- Spring Cloud 之 Config与动态路由.
一.简介 Spring Cloud Confg 是用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,它分为服务端与客户端两个部分.其中服务端也称为分布式配置中心,它是一个独立的微服务 ...
- spring cloud(三)服务提供与调用
服务提供 我们假设服务提供者有一个hello方法,可以根据传入的参数,提供输出“hello xxx,this is first messge”的服务 1.pom包配置 创建一个springboot项目 ...
- Spring Cloud(三):服务提供与调用
上一篇文章我们介绍了eureka服务注册中心的搭建,这篇文章介绍一下如何使用eureka服务注册中心,搭建一个简单的服务端注册服务,客户端去调用服务使用的案例. 案例中有三个角色:服务注册中心.服务提 ...
- spring cloud (八) Config client 和项目公共配置
1 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...
- spring cloud (七) Config server基于svn配置
1 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...
随机推荐
- greenplum资源队列
1.创建资源队列语法 Command: CREATE RESOURCE QUEUEDescription: create a new resource queue for workload m ...
- 程序包管理rpm和yum
Linux程序包管理: API:Application Programming Interface源码包 POSIX:Portable OS 程序源代码 --> 预处理 --> 编译 -- ...
- Codeforces 902D/901B - GCD of Polynomials
传送门:http://codeforces.com/contest/902/problem/D 本题是一个数学问题——多项式整除. 对于两个整数a.b,求最大公约数gcd(a,b)的辗转相除法的函数如 ...
- sublime常用插件总结 (立贴)
bracket highlighter 使用这个插件 显示成对标签的位置 {} () [] html标签等的位置
- ZOJ 2699 Police Cities
Police Cities Time Limit: 10 Seconds Memory Limit: 32768 KB Once upon the time there lived a ki ...
- Spring MVC自定义消息转换器(可解决Long类型数据传入前端精度丢失的问题)
1.前言 对于Long 类型的数据,如果我们在Controller层通过@ResponseBody将返回数据自动转换成json时,不做任何处理,而直接传给前端的话,在Long长度大于17位时会出现精度 ...
- Java循环遍历中直接修改遍历对象
Java 循环遍历中直接修改遍历对象如下,会报异常: for (ShopBaseInfo sp: sourceList) { if(sp.getId()==5){ sourceList.remove( ...
- innodb_support_xa=1
mysql> show create table t; CREATE TABLE `t` ( `id` ) NOT NULL AUTO_INCREMENT, `num` ) DEFAULT NU ...
- RecyclerView的使用(1)之HelloWorld
原创文章.转载请注明 http://blog.csdn.net/leejizhou/article/details/50670657 RecyclerView是伴随Android 5.0公布的新控件, ...
- 站点搭建从零開始(七) WordPress站点的完好
1.WordPress站点前后端经常使用语言简单介绍和执行过程 通常一个站点的整个构建过程中须要大量的技术支持,尤其是用到非常多种计算机语言.站点的构建主要分后端和前端两部分,后端代码在server上 ...