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 ...
随机推荐
- Java设计模式之 — 适配器(Adapter)
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9400141 今天一大早,你的leader就匆匆忙忙跑过来找到你:“快,快,紧急任务 ...
- UVA 10328 Coin Toss
Coin Toss Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: ...
- 数位dp无前导零
题目链接:http:// www.lydsy.com/JudgeOnline/problem.php?id=1026 #include <iostream> #include < ...
- javascript Prototype constructor的理解(转)
讲JS的构造的,这个比较清晰,但并不表示一定正确. 这几天一直在思考这个东东,感觉比以前理解更深入了. http://blog.csdn.net/chunqiuwei/article/details/ ...
- magento 在全站或者某页面增加外联js或者css的方法
1,在整站末尾增加外联资源 找到当前主题的布局文件cms.xml,在<default></default>添加如下代码: <reference name="be ...
- Ruby的case语句
Ruby的case语句 case语句使用的是===判断方式,可以进行更加广义的相等判断: 可以进行类型的判断,可以进行正则表达式的判断: array = ["a",1,nil] a ...
- java根据内容生成二维码图片
package util; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; ...
- HTML的表单form以及form内部标签
<html> <head> <title> form表单的使用 </title> <!-- 标签名称:form 表单标签 属性:action:提交 ...
- Android 四大组件学习之ContentProvider二
上节学习了什么是ContentProvider.以及ContentProvider的作用.以及什么是URL.本节就对上节学习的知识做一个实践,也就是定义自己的ContentProvider 好.实践是 ...
- TextView高级
前言 开门见山,这一篇博客主要讲一下在Android开发中,UI控件TextView的一些使用方式,并且通过四个例子实现一般项目中需要的效果来讲解TextView的使用.并且在之后的一段时间之内,都会 ...