SpringCloud(H版&alibaba)框架学习笔记

这篇博客介绍了SpringCloud H版的微服务入门,包括新建Maven父工程cloud2020,建立支付module cloud-provider-payment8001,以及消费者订单module的创建。详细讲解了RestTemplate的使用,订单服务如何调用支付服务,并进行了工程重构,创建公共module cloud-api-commons来消除代码冗余。
摘要由CSDN通过智能技术生成

微服务架构入门

SpringCloud  :  分布式微服务架构的一站式解决方案,是多种微服务架构落地技术的集合体,俗称微服务全家桶

服务注册与发现:EUREKA

服务负载均衡与用:NETFLIX OSS RIBBON

服务负载与调用:NETTFLIX

服务熔断降级:HYSTRIX

服务网关:Zuul

服务分布式配置:SpringCloud Config

服务开发:SpingBoot

SpringBoot 2.0版和SpringCloud H版 强烈建议使用SpringBoot 2.0以上

SpringBoot和SpringCloud之间版本有约束 H版对应2.2 G版对应2.1

开发使用的版本


cloud:Hoxton.SR1

springboot:2.2.2.RELEASE

cloud alibaba:2.1.0.RELEASE

java:java8

Maven 3.5以上

Mysql:5.7以上 

1. 新建Maven父工程 cloud2020

新建一个maven工程,用来多模块管理便于开发,会实现多个支付服务,一个订单服务,一个eureka 集群

maven 骨架选择 org.apache.maven.archetypes:maven-archetype-site

新建模块的五大步

  1. 新建 module
  2. 修改 pom 文件
  3. 配置 yml 文件
  4. 配置主启动类
  5. 业务代码

pom 文件

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.atguigu.springcloud</groupId>
  <artifactId>cloud2020</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>Maven</name>
  <!-- FIXME change it to the project's website -->
  <url>http://maven.apache.org/</url>
  <inceptionYear>2001</inceptionYear>

  <distributionManagement>
    <site>
      <id>website</id>
      <url>scp://webhost.company.com/www/website</url>
    </site>
  </distributionManagement>

  <!--统一管理jar包版本-->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <junit.version>4.12</junit.version>
    <log4j.version>1.2.17</log4j.version>
    <lombok.version>1.16.18</lombok.version>
    <mysql.version>8.0.12</mysql.version>
    <druid.version>1.1.16</druid.version>
    <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
  </properties>

  <!--子模块继承之后,提供作用:锁定版本+子module不用groupId和version-->
  <dependencyManagement>
    <dependencies>
      <!--spring boot 2.2.2-->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.2.2.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <!--spring cloud Hoxton.SR1-->
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Hoxton.SR1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <!--spring cloud alibaba 2.1.0.RELEASE-->
      <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-dependencies</artifactId>
        <version>2.1.0.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.version}</version>
      </dependency>
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>${druid.version}</version>
      </dependency>
      <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>${mybatis.spring.boot.version}</version>
      </dependency>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
      </dependency>
      <
你好!对于Spring Cloud Alibaba学习笔记,我可以为你提供一些基本的信息和指导。在学习Spring Cloud Alibaba之前,你可能需要对Spring CloudAlibaba的相关技术有一定的了解。 Spring Cloud Alibaba是基于Spring Cloud开发的一套微服务框架,它融合了阿里巴巴的中间件技术栈,提供了一系列开箱即用的解决方案,包括服务注册与发现、分布式配置管理、消息驱动等功能。它旨在帮助开发者快速构建微服务架构。 以下是一些学习Spring Cloud Alibaba的步骤和资源推荐: 1. 了解Spring CloudAlibaba的基础知识:在开始学习Spring Cloud Alibaba之前,你需要对Spring Cloud和阿里巴巴的相关技术有一定的了解。你可以先学习Spring Cloud的核心概念和基本使用方式,再深入了解阿里巴巴的中间件技术栈。 2. 官方文档:Spring Cloud Alibaba官方文档是学习的重要参考资料,你可以从官方文档中了解框架的核心概念、使用方式以及各个组件的详细说明。 3. 示例代码:官方文档中通常会提供一些示例代码,你可以通过运行示例代码来实践学习,加深对框架的理解。 4. 开发实践:尝试在自己的项目中应用Spring Cloud Alibaba,可以从简单的项目开始,逐步扩展和深入应用框架的各个功能。 5. 社区资源:参与Spring Cloud Alibaba的相关社区活动,例如论坛、博客、技术分享等,与其他开发者交流和学习。 希望以上信息对你有所帮助!如果你有更具体的问题,欢迎继续提问。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值