SpringCloud Config Server搭建
文章目录
- 1 创建Git仓库
- 2 创建应用配置文件
- 3 将应用配置文件commit到Git仓库中
- 4 创建Config Server应用
- 5 配置运行Config Server
- 6 访问Config Server
SpringCloud Config Server的作用实际上是充当Spring应用和存放在Git中的配置文件之间的媒介,为其他应用提供一个统一的配置管理中心,架构图如下:
图片出处: Config 简介以及搭建server端
关于SpringCloud Config的介绍可以参考:SpringCloud Config简介
本文介绍SpringCloud Config Server的搭建步骤。
1 创建Git仓库
这一步简单,随便创建一个目录,在该目录下执行下git init
即可。
当然也可以从GitHub或GitLab上创建一个仓库,再git clone
到本地。
2 创建应用配置文件
在上面创建的目录下,创建一个a-bootiful-client.properties
文件,文件内容:
message = Hello world
这里需要注意一下,Config Server中每个配置文件对应一个应用,如a-bootiful-client.properties
这个配置文件中保存的就是应用名为a-bootiful-client
的应用的配置。如果要保存所有应用通用的配置,可以放在application.properties
或application.yml
中,如果通用配置中的配置项和特定应用的配置项发生冲突,特定应用的配置项会覆盖调通用配置中的配置项。
3 将应用配置文件commit到Git仓库中
这里也有个地方需要注意的,Spring Config只能读取到commit到Git中的配置信息,只修改了配置文件没有commit是不会生效的。
执行以下命令,将应用配置文件commit到Git仓库中:
git add .
git commit -m 'add'
4 创建Config Server应用
为了方便,我们可以在https://start.spring.io创建一个Config Server模板应用,进入https://start.spring.io,依赖选择Config Server,填写包名等信息后点击GENERATE
按钮,生成一个Config Server项目的压缩包:
解压该压缩包,导入到Idea中(其他IDE应该也一样)。
5 配置运行Config Server
在src/main/resources/application.properties
加入以下配置:
server.port=8888
spring.cloud.config.server.git.uri=${HOME}/Documents/workspaces/git/springcloudconfig
server.port
修改应用的监听的端口为8888,防止和其他应用冲突。
spring.cloud.config.server.git.uri
指定了Git仓库的地址,即第一步我们创建的目录。
打开ConfigserverApplication.java
文件,生成的这个Java文件不知道怎么的少了一个注解@EnableConfigServer
,需要加上去,如下:
package com.example.configserver;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);}
}
完成上述配置以后不出意外的话run一下就可以运行起来了。
6 访问Config Server
打开浏览器,输入地址 http://localhost:8888/a-bootiful-client/default
,可以看到一下界面:
注意,地址中的a-bootiful-client
是第2步中创建的配置文件的名称,返回的Json数据中的source
即是配置文件中定义的配置信息。
SpringCloud Config Server搭建相关推荐
- 微服务SpringCloud—Config Server对称加密
配置内容的加解密 在Git仓库中明文存储配置属性的.很多场景下,对于某些敏感的配置内容(例如数据库账号.密码等),应当加密存储. Config对称加解密 1.安装JCE 默认情况下我们的JRE自带了J ...
- Spring-cloud Config Server 3种配置方式
1.config 默认Git加载 通过spring.cloud.config.server.git.uri指定配置信息存储的git地址,比如:https://github.com/xxx/config ...
- 配置SpringCloud Config Client连上Config Server
SpringCloud Config Client实际上就是连接到Config Server的普通应用,前面一篇文章 SpringCloud Config Server搭建 已经介绍了如何搭建一个Co ...
- 搭建SpringCloud配置中心 Config Server
项目地址: 链接:https://pan.baidu.com/s/1Mxo0ltvZbpz_r8mCU-mSpw 提取码:3j4a 问题解答: SpringCloud Config 分布式配置文件中 ...
- 带你入门SpringCloud统一配置 | SpringCloud Config
前言 在微服务中众多服务的配置必然会出现相同的配置,如果配置发生变化需要修改,一个个去修改然后重启项目的方案是绝对不可取的.而 SpringCloud Config 就是一个可以帮助你实现统一配置选择 ...
- Spring Cloud教程– Spring Cloud Config Server简介
问题 SpringBoot在通过属性或YAML文件外部化配置属性方面提供了很大的灵活性. 我们还可以使用特定于配置文件的配置文件(例如application.properties , applicat ...
- 跟着狂神学SpringCloud(Rest环境搭建+Eureka服务注册与发现+ribbon+Feign负载均衡+Hystrix+服务熔断+Zuul路由网关+SpringCloud config分布)
跟着狂神学SpringCloud SpringCloud 回顾之前的知识- JavaSE 数据库 前端 Servlet Http Mybatis Spring SpringMVC SpringBoot ...
- springcloud 分布式配置中心 config server config client
---------------------------------------------------------------------------------------------------- ...
- SpringCloud:Eureka Config项目搭建(Gradle项目)
Eureka Config分为Config Server 和Config Client两部分. Config Server部分: gradle配置: // https://mvnrepository. ...
最新文章
- More than one file was found with OS independent path 'META-INF/rxjava.properties
- python爬虫高考成绩
- 动态规划算法-06Longest Valid Parentheses问题
- STM32F1笔记(一)GPIO输出
- JAVA入门级教学之(public class和class的区别)
- ASP注入漏洞基础教程(二)
- mysql集群之MHA简单搭建
- 我们用大数据创造没人能理解的人工智能
- 4.7UF400V 10*8.4贴片铝电解电容封装尺寸
- python 006 __ 小斌文档 | 特殊字符的使用
- 如何在VMware Workstation上安装Nutanix CE的解决方案
- [翻译]Orchard如何工作
- 更换服务器IP有哪些步骤,如何操作。
- 2022第四届长安杯电子取证竞赛 服务器赛时思路题解 Zodi4c
- 十进制小数转化为二进制小数
- 二维图像卷积之后尺寸计算
- python:爬取租房100页数据
- How to prevent subsequent initialization in Android
- 【图像去噪】基于matlab多种自适应均值滤波图像去噪【含Matlab 1843期】
- linux清空日志到黑洞,Linux中的黑洞(black hole)-/dev/null