本文通过config server连接git仓库来实现配置中心,除了git还可以使用svn或者系统本地目录都行。需要JAVA Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码 一零三八七七四六二六

引入依赖

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency>
</dependencies>
复制代码

spring-cloud-config-server这个就是配置中心server的依赖。

配置中心做到高可用本身也需要向注册中心注册自己的实例,所以需求引用spring-cloud-starter-eureka依赖。

添加启动类,开启Config Server功能

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

@EnableConfigServer:即开启配置服务器的功能。

@EnableDiscoveryClient:开启自动注册客户端,默认情况下,ServiceRegistry实现将自动注册正在运行的服务。如注册中心使用是Eureka,这里也可以使用的@EnableEurekaClient注解。

添加Config配置

spring: application:name: config-centerprofiles:active: config-center1cloud: config:server:git:uri: ${git.uri}searchPaths: ${git.searchPaths}username: ${git.username}password: ${git.password}basedir: ${git.basedir}clone-on-start: trueforce-pull: trueeureka:instance: prefer-ip-address: true  instance-id: ${spring.cloud.client.ipAddress}:${server.port}lease-expiration-duration-in-seconds: ${lease-expiration-duration-in-seconds}lease-renewal-interval-in-seconds: ${lease-renewal-interval-in-seconds}client:serviceUrl:defaultZone: ${register-center.urls}---
spring:profiles: config-center1server: port: ${config-center1.server.port}---
spring: profiles: config-center2server: port: ${config-center2.server.port}
复制代码

这里配置了两台Config Server,都注册到了两台注册中心上。

Maven filter配置

#git
git.uri=http://gitlab.example.com/test/config.git
git.username=root
git.password=root
git.searchPaths=config-center
git.basedir=f:/config/config-center/git
复制代码

Spring Cloud Git配置详解

spring.cloud.config.server.git.uri:git仓库地址。

spring.cloud.config.server.git.searchPaths:git仓库搜索目录。

spring.cloud.config.server.git.username:连接git的用户名。

spring.cloud.config.server.git.password:连接git的用户名密码。

spring.cloud.config.server.git.basedir:配置中心在本地缓存配置的目录。

spring.cloud.config.server.git.clone-on-start:配置为true表示启动时就克隆配置缓存到本地。

spring.cloud.config.server.git.force-pull:配置为true表示如果本地副本是脏的,将使Spring Cloud Config Server强制从远程存储库拉取配置。

启动配置中心

分别启动以下配置中心,使用不同的Profile指定端口。

spring-boot:run -Drun.profiles=config-center1 -P dev
spring-boot:run -Drun.profiles=config-center2 -P dev
复制代码

java B2B2C源码电子商务平台

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

java B2B2C源码电子商务平台 -SpringCloud配置中心高可用搭建相关推荐

  1. java B2B2C源码电子商务平台 -commonservice-config配置服务搭建

    2019独角兽企业重金招聘Python工程师标准>>> Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持.使用Config Server,您可以在 ...

  2. java B2B2C源码电子商务平台 -SpringCloud服务相互调用RestTemplate

    Springcloud中的服务消费,就需要我们服务之前相互发请求了.之前我们都是想着用http请求相关的交互,用的比较多的是apache httpcomponents ,现在springboot提供了 ...

  3. java B2B2C源码电子商务平台-配置中心svn示例和refresh

    国内很多公司都使用的svn来做代码的版本控制,我们先介绍以下如何使用svn+Spring Cloud Config来做配置中心.需要了解电子商务平台源码可加企鹅邱邱 一零三八七七四六二六 svn版本 ...

  4. java B2B2C源码电子商务平台 - Zuul回退机制

    1.在一些不稳定因素导致路由后面的微服务宕机或者无响应时,zuul 就会累计大量的请求,久而久之基本上所有的请求都会超时,但是请求链接数却不断的在增加,不断的占用资源池不能结束知道超时消耗殆尽导致zu ...

  5. java B2B2C源码电子商务平台-基于Consul的分布式锁实现

    分布式锁实现 需要JAVA Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码:壹零叁八柒柒肆六二六 基于Consul的分布式锁主要利用Key/Value存储API中的ac ...

  6. java B2B2C源码电子商务平台 --zuul跨域访问问题

    springcloud微服务框架,是一组组件,eureka服务注册中心,zuul路由等等 一般都是在zuul上配好url路径映射到各个服务,所以对外都是访问zuul服务的端口,但是在web服务设置了跨 ...

  7. java B2B2C源码电子商务平台

    springCloud是基于SpringBoot的一整套实现微服务的框架.他提供了微服务开发所需的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布式会话和集群状态管理等组 ...

  8. java B2B2C源码电子商务平台 ---搭建Eureka注册中心

    一 创建一个Spring Boot工程,命名为eureka-server,并在pom.xml中引入必要的依赖,代码如下.愿意了解源码的朋友直接求求交流分享技术:二一四七七七五六三三 <paren ...

  9. SpringCloud配置中心高可用搭建

    本文通过config server连接git仓库来实现配置中心,除了git还可以使用svn或者系统本地目录都行. 引入依赖 <dependencies><dependency> ...

最新文章

  1. Liunx 安装mysql 5.6.16
  2. UITabBarController使用总结
  3. 如何在android进行ltp测试,Android系统完整性度量架构IMA-EVM
  4. 能够让机器狗学会灭火, ModelArts3.0让AI离我们又近一步
  5. CString::Format出现的Buffer too small错误
  6. html做table某一列的合计,Jquery、js计算table列合计
  7. 基于大数据平台的毕业设计
  8. 组合逻辑电路的分析与设计
  9. django运行错误:wrong number of arguments for ‘set‘ command
  10. 深度xp系统安装教程
  11. 很棒的图片浏览器代码,源码研究
  12. 企业为何都用电子招投标 现代电子招投标系统介绍
  13. must implement OnFragmentInteractionListener/ Fragment与Activity,Fragment与Fragment之间的信息传递
  14. 保研面试/考研复试线性代数问题整理
  15. 每周一磁 · 矫顽力Hcb和内禀矫顽力Hcj
  16. UILabel的使用
  17. Eclipse 快捷键 mac
  18. rgb格式颜色与#000000十六进制格式颜色的转换原理
  19. Vue React Angular之三国杀,web前端入坑第六篇 上
  20. Mysql ——区、段、表空间 、碎片区

热门文章

  1. 怎么查找那台电脑中了ARP病毒
  2. linux命令-- pstack命令(跟踪进程栈)
  3. [C/C++面试题]-错题笔记与解析
  4. [BUUCTF-pwn]——mrctf2020_easyoverflow
  5. 类的成员函数与内联以及静态成员
  6. 铁幕(Iron Curtain)
  7. Java线程之守护线程(Daemon) .
  8. Vue_注册登录(短信验证码登录)
  9. nodejs(6)express学习
  10. spring cloud各组件详解