微服务java_b2b商城系统_java商城源码100%开源适合2次开发-(六)分布式配置中心(Spring Cloud Config)...
发布日期:2021-09-03 18:04:46 浏览次数:2 分类:技术文章

本文共 3460 字,大约阅读时间需要 11 分钟。

一、简介

在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在Spring Cloud中,有分布式配置中心组件spring cloud config ,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中。在spring cloud config 组件中,分两个角色,一是config server,二是config client。

二、构建Config Server

创建一个spring-boot项目,取名为config-server,其pom.xml:

4.0.0
com.forezp
config-server
0.0.1-SNAPSHOT
jar
config-server
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.5.2.RELEASE
UTF-8
UTF-8
1.8
org.springframework.cloud
spring-cloud-config-server
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.cloud
spring-cloud-dependencies
Camden.SR6
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false
复制代码

在程序的入口Application类加上@EnableConfigServer注解开启配置服务器的功能,代码如下:

@SpringBootApplication@EnableConfigServerpublic class ConfigServerApplication {     public static void main(String[] args) {        SpringApplication.run(ConfigServerApplication.class, args);    }}复制代码

需要在程序的配置文件application.properties文件配置以下:

spring.application.name=config-serverserver.port=8888spring.cloud.config.server.git.uri=https://github.com/forezp/SpringcloudConfig/spring.cloud.config.server.git.searchPaths=respospring.cloud.config.label=masterspring.cloud.config.server.git.username=your usernamespring.cloud.config.server.git.password=your password复制代码
  • spring.cloud.config.server.git.uri:配置git仓库地址
  • spring.cloud.config.server.git.searchPaths:配置仓库路径
  • spring.cloud.config.label:配置仓库的分支
  • spring.cloud.config.server.git.username:访问git仓库的用户名
  • spring.cloud.config.server.git.password:访问git仓库的用户密码

启动程序:访问

{
"name":"foo","profiles":["dev"],"label":"master","version":"792ffc77c03f4b138d28e89b576900ac5e01a44b","state":null,"propertySources":[]}复制代码

架构代码如下:

Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六

转载于:https://juejin.im/post/5c6501a1518825627d3713fb

转载地址:https://blog.csdn.net/weixin_34194317/article/details/91485397 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:基于 DataLakeAnalytics 做跨地域的数据分析
下一篇:开发区块链交易所的安全性如何保证?

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月04日 00时16分33秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

【面试篇】Java对象的hashCode()相同,equals()一定为true吗? 2019-04-26
【面试篇】Java中static和final关键字的作用是什么? 2019-04-26
【面试篇】Java中接口和抽象类的区别是什么? 2019-04-26
【Java网络编程与IO流】Java中IO流分为几种?字符流、字节流、缓冲流、输入流、输出流、节点流、处理流 2019-04-26
【Java网络编程与IO流】Java中BIO、NIO、AIO的区别是什么? 2019-04-26
【Leetcode刷题篇】leetcode136 只出现一次的数字 2019-04-26
spring boot整合thymeleaf,支持JSP和HTML页面开发 2019-04-26
【Java网络编程与IO流】Spring boot整合SSE实现服务器实时推送流信息 2019-04-26
【Java网络编程与IO流】SpringBoot + WebSocket + Netty实现实时的服务器消息推送 2019-04-26
【Leetcode刷题篇】leetcode141 环形链表II 2019-04-26
【Leetcode刷题篇】leetcode160 相交链表 2019-04-26
【Leetcode刷题篇】leetcode169 多数元素 2019-04-26
【Leetcode刷题篇】leetcode461 汉明距离 2019-04-26
【Leetcode刷题篇】leetcode204 计数质数 2019-04-26
【Leetcode刷题篇】leetcode70 爬楼梯 2019-04-26
【Leetcode刷题篇】leetcode739 每日温度 2019-04-26
【Leetcode刷题篇】leetcode121买卖股票的最佳时机 2019-04-26
【面试篇】Java多线程并发-Java关键字volatile详解 2019-04-26
【面试篇】Java的代理模式-静态代理和动态代理详解 2019-04-26
【面试篇】 Java对象拷贝(对象克隆 对象复制) 2019-04-26