Spring Cloud项目构建(上)

实验目的

  1. 了解Spring Cloud的概念和特点
  2. 掌握Spring Cloud Eureka的使用
  3. 掌握Spring Cloud Ribbon的使用
  4. 掌握Spring Cloud Hystrix的使用
  5. 掌握Spring Cloud Zuul的使用
  6. 掌握Spring Cloud Config的使用

实验要求

  1. SpringCloud搭建
  2. 服务发现
  3. 客户端负载均衡
  4. 服务容错保护
  5. API网关服务
  6. 分布式配置管理

实验步骤

 

任务一 :服务发现

一、搭建Maven父项目,引入Spring Cloud工具集依赖:

Spring Cloud项目构建

Spring Cloud项目构建

Spring Cloud项目构建

Spring Cloud项目构建

Spring Cloud项目构建

Spring Cloud项目构建

二、搭建Eureka Serve服务注册中心子Modle项目

1、引入注册中心Eureka Server依赖:

Spring Cloud项目构建

2、编写配置文件,设置Eureka Server服务地址:

Spring Cloud项目构建

3、在项目的引导类上添加注解@EnableEurekaServer:

Spring Cloud项目构建

4.Eureka Server服务注册中心启动效果:

Spring Cloud项目构建

Spring Cloud项目构建

三、搭建Eureka Client客户端子Modle项目

1、引入客户端Eureka依赖:

Spring Cloud项目构建

2、编写配置文件,设置Eureka Server服务地址:

Spring Cloud项目构建

3、在项目的引导类上添加注解@EnableEurekaClient:

Spring Cloud项目构建

4、Eureka Client客户端启动效果:

Spring Cloud项目构建

四、服务间调用

1.搭建订单服务工程

Spring Cloud项目构建

Spring Cloud项目构建

Spring Cloud项目构建

2.编写用户服务功能

Spring Cloud项目构建

Spring Cloud项目构建

3.启动服务应用,测试服务调用

Spring Cloud项目构建

Spring Cloud项目构建

任务二 客户端负载均衡

  • Ribbon的使用
  1. 在客户端工程引导类中的restTemplate()方法上添加@l oadBalanced注解:Spring Cloud项目构建
  2. 使用服务名进行微服务远程调用:Spring Cloud项目构建
  3. 创建服务监听类,来演示负载均衡的实现效果:Spring Cloud项目构建
  4. 启动服务,测试应用
  5. Spring Cloud项目构建
  6. Spring Cloud项目构建
  7. Spring Cloud项目构建
  8. Spring Cloud项目构建

     

 

 

相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2022-03-10
  • 2021-09-04
  • 2021-10-06
  • 2021-10-06
猜你喜欢
  • 2022-12-23
  • 2021-07-28
  • 2021-09-25
  • 2021-09-30
  • 2021-04-01
  • 2021-06-16
  • 2021-12-28
相关资源
相似解决方案