spring-cloud-config 搭建-入门级(一)
明确几个工程的端口
工程名 | 作用 | 端口 |
---|---|---|
config-server | config的配置服务端 | 配置了8080dev, 8082prd |
config-client | 为了测试调用的demo | 8889 |
eureka-provider | 实际项目演练的工程 | 配置了8080dev, 8082prd |
eureka-server | eureka 的服务注册中心 | 8761 |
本文github地址
远端配置文件
github.com/xueshuiyy/s…
配置client和server端
github.com/xueshuiyy/s…
明确远端配置文件工程的路径和文件名
我的git上的路径:
DEMO 搭建过程
父工程
父工程引入server和client都需要的starter-config
<!-- 引入spring cloud 的config依赖 -->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId>
</dependency>
复制代码
必须要指定springcloud的版本!
<!-- 依赖管理 -->
<!-- spring-cloud-version 在properties里配置:
<spring-cloud-version>Greenwich.SR1</spring-cloud-version>
-->
<dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud-version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement>
复制代码
Server端
1. 在pom中 指定好父工程
<parent><groupId>lin.springcloud</groupId><artifactId>spring-cloud-config-lin</artifactId><version>0.0.1-SNAPSHOT</version><relativePath/> <!-- lookup parent from repository -->
</parent>
复制代码
2. 依赖config-server
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId>
</dependency>
复制代码
主类添加@EnableConfigServer注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerApplication.class, args);}}
复制代码
配置文件
server.port: 8888# 配置git仓库地址
spring.cloud.config.server.git.uri=https://github.com/xueshuiyy/spring-cloud-config-center.git
# 配置仓库路径,下图圈红的就是这个文件夹名
spring.cloud.config.server.git.search-paths=clientconfig
# 配置仓库的分支
spring.cloud.config.label=master
# 访问git仓库的用户名
spring.cloud.config.server.git.username=xueshuiyy
# 访问git仓库的用户密码 如果Git仓库为公开仓库,可以不填写用户名和密码,如果是私有仓库需要填写
spring.cloud.config.server.git.password=
复制代码
Client端
配置依赖
由于父工程已经配置了 spring-cloud-starter-config 的依赖了,所以Client就不需要在配置了。只是需要用rest测试一下,所以引入web的依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
复制代码
配置文件
做一个bootstrap.yml(properties)的文件,application.properties文件就可写可不写了,bootstrap 的配置文件会覆盖掉application的配置文件。联想到双亲委派机制(向上委托,向下加载),bootstrap-> extend -> app
server.port=8889
# 和git里的文件名对应,下图的圈红
spring.application.name=config-client
# 远程仓库的分支
spring.cloud.config.label=master
# dev 开发环境配置文件 | test 测试环境 | pro 正式环境
# 和git里的文件名对应,我们可以配置多个文件来区分不同环境的配置
spring.cloud.config.profile=dat
# 指明配置服务中心的网址
spring.cloud.config.uri= http://localhost:8888/
复制代码
搭建完毕的访问地址
server端访问地址
/{application}/{profile}[/{label}] http://localhost:8888/config-client/dev
/{application}-{profile}.yml /{application}-{profile}.properties http://localhost:8888/config-client-dev.properties
/{label}/{application}-{profile}.properties /{label}/{application}-{profile}.yml http://localhost:8888/master/config-client-dev.properties
证明配置服务中心可以从远程程序获取配置信息。
client端访问地址
http://localhost:8889/hi
搭建后优化
1 先把所有的properties 改成 yml
2 优化配置中心的配置文件为一个
这样配置完毕后,启动的端口也完全由 client的配置文件 bootstrap.xml 配置的环境来决定了
3 验证 用config-client工程验证
http://localhost:8082/hi 结果:
转载于:https://juejin.im/post/5cd52ff76fb9a0321556fd2b
spring-cloud-config 搭建-入门级(一)相关推荐
- spring cloud config注意点(疑问)
2019独角兽企业重金招聘Python工程师标准>>> 当使用spring cloud config搭建高可用时.项目结构 config-eureka config-server c ...
- 【Spring Cloud 基础设施搭建系列】Spring Cloud Demo项目 Spring Cloud Config Client 失败快速响应与超时重试
文章目录 Spring Cloud Config Client 失败快速响应与重试 测试 参考 源代码 Spring Cloud Config Client 失败快速响应与重试 Spring Clou ...
- spring cloud config将配置存储在数据库中
点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓库, ...
- 为Spring Cloud Config插上管理的翅膀
最近一致在更新Spring Cloud Config的相关内容,主要也是为这篇埋个伏笔,相信不少调研过Spring Cloud Config的用户都会吐槽它的管理能力太弱.因此,就有了下面为讲推荐的这 ...
- spring cloud config将配置存储在数据库中 1
转载请标明出处: https://blog.csdn.net/forezp/... 本文出自方志朋的博客 Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓 ...
- springcloud 之 配置中心服务 spring cloud config
开门见山,不做过多的陈述,简单说一下配置中心的作用:在我们的实际项目开发中,我们一般都是一个项目一套配置,就像我之前的springboot项目,每个项目下都有一套resources/applicati ...
- spring cloud 入门系列七:基于Git存储的分布式配置中心--Spring Cloud Config
我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config. 它用来 ...
- Spring Cloud Config服务端配置细节(一)
上篇文章我们看了Spring Cloud中分布式配置中心的一个基本使用,这里边还涉及到许多细节,本文我们就来看看服务端配置中的一些细节. 本文是Spring Cloud系列的第二十三篇文章,了解前二十 ...
- Spring Cloud Config统一管理微服务配置
一Spring Cloud Config背景及简介 # 集中管理的需求:一个使用微服务架构的应用系统可能会包括成百上千个微服务,因此集中管理很有必要 # 不同环境不同配置:例如数据源在不同的环境(开发 ...
- 《深入理解 Spring Cloud 与微服务构建》第十三章 配置中心 Spring Cloud Config
<深入理解 Spring Cloud 与微服务构建>第十三章 配置中心 Spring Cloud Config 文章目录 <深入理解 Spring Cloud 与微服务构建>第 ...
最新文章
- 蜗蜗 Linux内核芬妮下,Linux内核的整体架构
- 数据库水平切分的实现原理解析---分库,分表,主从,集群,负载均衡器
- 牛客多校9 - Groundhog Looking Dowdy(尺取)
- SPEL + 中的错误处理
- Java 8 Friday:更多功能关系转换
- net.conn read 判断数据读取完毕_1.5 read, write, exit系统调用
- Docker时代来临,你的团队准备好了吗?
- OpenGL超级宝典第五版 Windows + VS2013配置
- win10显示rpc服务器不可用,win10系统RpC服务器不可用的详细办法
- U8常用的二次开发方式
- 神经网络分析教学目标,神经网络分析教学反思
- php中where条件whereRaw,「laravel whereRaw 和 where(DB::raw(''))」- 海风纷飞Blog
- php java扩展模块_php扩展模块装安装
- 会员管理-小程序-免费使用体验
- 程序员生存定律-六个程序员的故事(2) .
- qt 设置背景图片方法
- 【张小平工作日志】同一目录下,Maven resource使用include与exclude实现过滤
- CentOS 7 安装 Postfix Dovecot
- ZYNQ7035使用FDMA读写PL DDR
- 教你如何用一行代码获取免费的QQ气泡框