server端改造

1、添加依赖

<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-starter-eureka包,来添加对eureka的支持。

2、配置文件

server:
server:port: 8001
spring:application:name: spring-cloud-config-servercloud:config:server:git:uri: https://github.com/ityouknow/spring-cloud-starter/     # 配置git仓库的地址search-paths: config-repo                             # git仓库地址下的相对地址,可以配置多个,用,分割。username: username                                        # git仓库的账号password: password                                    # git仓库的密码
eureka:client:serviceUrl:defaultZone: http://localhost:8000/eureka/   ## 注册中心eurka地址复制代码

增加了eureka注册中心的配置

3、启动类

启动类添加@EnableDiscoveryClient激活对配置中心的支持

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

这样server端的改造就完成了。先启动eureka注册中心,在启动server端,在浏览器中访问:http://localhost:8000/就会看到server端已经注册了到注册中心了。

按照上篇的测试步骤对server端进行测试服务正常。

客户端改造

1、添加依赖

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

需要多引入spring-cloud-starter-eureka包,来添加对eureka的支持。

2、配置文件

spring.application.name=spring-cloud-config-client
server.port=8002spring.cloud.config.name=neo-config
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=spring-cloud-config-servereureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/复制代码

主要是去掉了spring.cloud.config.uri直接指向server端地址的配置,增加了最后的三个配置:

  • spring.cloud.config.discovery.enabled :开启Config服务发现支持
  • spring.cloud.config.discovery.serviceId :指定server端的name,也就是server端spring.application.name的值
  • eureka.client.serviceUrl.defaultZone :指向配置中心的地址

这三个配置文件都需要放到bootstrap.properties的配置中

3、启动类

启动类添加@EnableDiscoveryClient激活对配置中心的支持

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

启动client端,在浏览器中访问:http://localhost:8000/ 就会看到server端和client端都已经注册了到注册中心了。

高可用

为了模拟生产集群环境,我们改动server端的端口为8003,再启动一个server端来做服务的负载,提供高可用的server端支持。

如上图就可发现会有两个server端同时提供配置中心的服务,防止某一台down掉之后影响整个系统的使用。

我们先单独测试服务端,分别访问:http://localhost:8001/neo-config/devhttp://localhost:8003/neo-config/dev返回信息:

{"name": "neo-config", "profiles": ["dev"], "label": null, "version": null, "state": null, "propertySources": [{"name": "https://github.com/ityouknow/spring-cloud-starter/config-repo/neo-config-dev.properties", "source": {"neo.hello": "hello im dev"}}]
}复制代码

说明两个server端都正常读取到了配置信息。

整体架构如下:

完整项目的源码来源

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

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

(八)JAVA springcloud ssm b2b2c多用户商城系统源码:配置中心服务化和高可用相关推荐

  1. JAVA springboot ssm b2b2c多用户商城系统源码-SSO单点登录之OAuth2.0登录流程(2)

    上一篇是站在巨人的肩膀上去研究OAuth2.0,也是为了快速帮助大家认识OAuth2.0,闲话少说,我根据框架中OAuth2.0的使用总结,画了一个简单的流程图(根据用户名+密码实现OAuth2.0的 ...

  2. JAVA springboot ssm b2b2c多用户商城系统源码(三)SpringBoot用JdbcTemplates访问Mysql

    准备工作 jdk 1.8 maven 3.0 idea mysql 初始化mysql: -- create table `account` DROP TABLE `account` IF EXISTS ...

  3. JAVA springboot ssm b2b2c多用户商城系统源码:服务消费(基础)...

    使用LoadBalancerClient 在Spring Cloud Commons中提供了大量的与服务治理相关的抽象接口,包括DiscoveryClient.这里我们即将介绍的LoadBalance ...

  4. JAVA springboot ssm b2b2c多用户商城系统源码(三):服务提供与调用

    上一篇文章我们介绍了eureka服务注册中心的搭建,这篇文章介绍一下如何使用eureka服务注册中心,搭建一个简单的服务端注册服务,客户端去调用服务使用的案例. 案例中有三个角色:服务注册中心.服务提 ...

  5. JAVA springcloud ssm b2b2c多用户商城系统-docker-hystrix-dashboard-turbine(九)

    简介 spring cloud b2b2c电子商务社交平台源码请加企鹅求求:一零三八七七四六二六.Hystrix的主要优点之一是它收集关于每个HystrixCommand的一套指标.Hystrix仪表 ...

  6. JAVA ssm b2b2c多用户商城系统源码 (十二)springboot集成apidoc

    首先声明下,apidoc是基于注释来生成文档的,它不基于任何框架,而且支持大多数编程语言,为了springboot系列的完整性,所以标了个题. 一.apidoc简介 apidoc通过在你代码的注释来生 ...

  7. JAVA ssm b2b2c多用户商城系统源码

    最近公司要开发商城,让我多方咨询,最后看了很多,要不就是代码.表字段注释不全,要不就是bug多,要么就是文档缺少,最后决定自己开发一套商城. 下面是开发的一些心得体会,权且记录下来,给自己做个记录把. ...

  8. JAVA b2b2c多用户商城系统源码-服务发现服务端EurekaServer微服务

    一.大致介绍 1.众所周知,在现在互联网开发中,访问地址的IP和端口号是动态的,一个服务停掉再重新启用后IP和端口就可能发生了改变,所以用硬编码是肯定不行了.于是我们尝试使用新的技术来解决这一难题.需 ...

  9. JooLun B2B2C多用户商城系统源码—多终端,无加密,不限域名,专业二开

    Uniapp是目前商城开发前端技术中的热门,Uniapp的大火让开发者和企业都很兴奋,对于uniapp开发的商城源码,优点非常明显,就是开发成本低,uniapp商城源码编写一套源代码就能打包成小程序. ...

最新文章

  1. struct stat结构体的详解和用法
  2. IT运维人员追女友必备神器之运维开发实战程序案例
  3. android设置title字体大小,android setTitle怎么实现字体的大小
  4. 不可错过!普渡大学最新《机器学习》课程
  5. 牛顿二项式定理计算平方根
  6. 吉首大学2019年程序设计竞赛-F 天花乱坠
  7. 【PyTorch】中view()==>相当于numpy中resize()、reshape()的功能
  8. PHP编译configure时常见错误(转)
  9. 3种方法实现Android按钮的点击事件,建议收藏!
  10. PETSHOP模式IDAL,SQLSERVERDAL,存储过程以及模型类代码的生成工具
  11. springboot2.x整合JavaMail以qq邮箱发送邮件
  12. 评中级工程师职称计算机,评中级工程师职称及注意事项
  13. 通达信公式解密工具5.05
  14. ORACLE导入unl
  15. Unity开发OpenXR | (二)使用 OpenXR 制作一款简单VR示例场景 的全过程详细教程,包含两个实战案例。
  16. 超级码力在线编程大赛初赛 第2场 【题解】
  17. Verilog HDL——运算符
  18. ubuntu18升级/安装cmake 超详细(亲测成功,2022年7月13日)
  19. 河北单招计算机的考试试题,河北单招试题
  20. 三郎前端特效学习源代码:图片主页轮播组件

热门文章

  1. ACM第一次集训 - 动态规划问题
  2. JS 字符串常用函数
  3. Python之smtpd及smtplib(邮件服务器及客户端)
  4. Lua 的table遍历 【转】
  5. 数据结构期末复习(に)--链式栈定义及使用
  6. [注]什么是用户?估计90%人不知道
  7. 格密码教程(五):Babai‘s algorithm和求解apprCVP算法
  8. 一图梳理企业数据治理的8项举措
  9. wpf datepicker 选择时分秒_[Angular 组件库 NG-ZORRO 基础入门] - DatePicker
  10. 程序员必备的GitHub加速指南,真香!