前言:Spring Cloud Alibaba是目前主流的分布式微服务架构,本文主要讲解了在IDEA中如何搭建Spring Cloud Alibaba环境,以及介绍Spring Cloud Alibaba各个版本之间的关系和搭建Spring Cloud前的准备工作。

Spring Cloud Alibaba官方文档(中文)

Spring Cloud官网

前置准备

Spring Cloud Alibaba需要依赖 Java 环境运行,同时还需要配置 Maven 环境,确保是以下版本:

  1. JDK 1.8+:安装
  2. Maven 3.2.x+:安装

版本说明

查看官网的版本说明

组件版本关系

下图中版本关系无需自己设置,在Spring Cloud Alibaba 版本管理器spring-cloud-alibaba-dependencies已经配置,引入该依赖即可

毕业版本依赖关系(推荐使用)

不同的Spring Cloud Alibaba版本之间的版本依赖关系不同,创建时需要自己查看官网说明,选择RELEASE版本(发行版)

搭建方法

pom.xml

<properties>
<spring.cloud.alibaba.version>2.2.6.RELEASE</spring.cloud.alibaba.version>
<spring.boot.version>2.3.2.RELEASE</spring.boot.version>
<spring.cloud.version>Hoxton.SR9</spring.cloud-version>
</properties> <dependencyManagement>
<dependencies>
<!--Spring Cloud Alibaba 版本管理器-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>{spring.cloud.alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--Spring Boot 版本管理器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--Spring Cloud 版本管理器-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Spring Boot 版本管理器里面的spring-boot-dependenciesspring-boot-starter-parent是一样,两种名字都可以

Spring脚手架创建

构建项目:约定 > 配置 > 编码

父工程

  1. 在IDEA中新建父工程(父工程用于约定整个SpringCloud项目的版本)

  1. 选择 Spring Initializr

  1. 填写项目信息,注意:选择Maven POM和Java版本(JDK)

    选择Maven POM创建项目不会创建src文件,只有pom.xml文件,父工程足够使用

  1. 选择Spring Boot版本(随便选择,后面需要修改)

  1. 检查项目名称和保存位置,点击Finish。等待创建完成,出现界面则创建完成

  1. 完成创建后,打开pom.xml文件添加如下内容,添加SpringCloudAlibaba、SpringBoot和SpringCloud的依赖

pom.xml

<properties>
<spring.cloud.alibaba.version>2.2.6.RELEASE</spring.cloud.alibaba.version>
<spring.boot.version>2.3.2.RELEASE</spring.boot.version>
<spring.cloud.version>Hoxton.SR9</spring.cloud-version>
</properties> <dependencyManagement>
<dependencies>
<!--Spring Cloud Alibaba 版本管理器-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>{spring.cloud.alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--Spring Boot 版本管理器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--Spring Cloud 版本管理器-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Spring Boot 版本管理器里面的spring-boot-dependenciesspring-boot-starter-parent是一样,两种名字都可以

  1. 父工程搭建完成,其他如服务发现注册、配置中心、消息总线、负载均衡、断路器、数据监控等组件需要时在父工程的pom.xml中引入相关依赖即可,这里先略过

子模块

  1. 在父工程中新建模块

  1. 选择Maven,点击Next。

  1. 填写子模块名(服务名)

相比于Spring官方提供的脚手架,使用阿里云脚手架来创建会更加快捷方便,阿里云重点面向微服务项目

IDEA设置

添加SpringBoot的服务选项卡

快速管理各个服务的状态

  1. 编辑配置

  1. 添加SpringBoot服务

  1. 找到 SpringBoot

  1. 点击OK后,下方就会出现一个Services,用于查看Spring Boot的微服务状态

服务改名

  1. 右键点击服务,选择下图的红框打开

  1. 修改配置信息

Spring Cloud Alibaba环境搭建的更多相关文章

  1. Spring Cloud Alibaba+Nacos搭建微服务架构

    1. Spring Cloud Alibaba 简介    Spring Cloud Alibaba是阿里巴巴为分布式应用提供的一站式解决方案,能够更方便快捷地搭建分布式平台,nacos拥有着替换eu ...

  2. Docker composer搭建Spring Cloud Alibaba 运行环境(二)

    " Spring Cloud Alibaba要用到的组件很多,注册中心nacos, 限流sentinel, 数据库,网关等等.由于用到的组件相对较多,部署会很繁琐,最关键的是没有资源服务器, ...

  3. Spring Cloud Alibaba(7)---docker-compose搭建nacos1.4.0集群

    docker-compose搭建nacos1.4.0集群 有关Nacos之前写过四篇文章. Spring Cloud Alibaba(3)---Nacos概述 Spring Cloud Alibaba ...

  4. Spring Cloud Alibaba(10)---Sentinel控制台搭建+整合SpringCloudAlibaba

    上一篇博客讲了Sentinel一些概念性的东西 Spring Cloud Alibaba(9)---Sentinel概述 这篇博客主要讲 Sentinel控制台搭建,和 整合SpringCloudAl ...

  5. Spring Cloud Alibaba基础教程:Nacos的集群部署

    继续说说生产环境的Nacos搭建,通过上一篇<Spring Cloud Alibaba基础教程:Nacos的数据持久化>的介绍,我们已经知道Nacos对配置信息的存储原理,在集群搭建的时候 ...

  6. Spring Cloud Alibaba到底坑不坑?

    之前我发过一篇<说说我为什么看好Spring Cloud Alibaba>,然后这两天有网友给我转了这篇文章<坑爹项目spring-cloud-alibaba,我们也来一个>, ...

  7. Spring Cloud Alibaba基础教程:Nacos的数据持久化

    前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...

  8. Spring Cloud Alibaba | 序言

    目录 Spring Cloud Alibaba | 序言 1. Spring Cloud Alibaba是什么? 2. 主要功能 3. 组件 4. 版本说明 4.1 版本依赖关系 4.2 组件版本关系 ...

  9. spring cloud alibaba 简介

    ### Spring Cloud Alibaba [官方github地址](https://github.com/alibaba/spring-cloud-alibaba) Spring Cloud ...

随机推荐

  1. 【原创】自制string类型(已完成)

    这篇文章首发于360doc http://www.360doc.com/content/21/0526/17/73755266_979099504.shtml ,其实360doc里面的那个也是我的帐号 ...

  2. 引人遐想,用 Python 获取你想要的 “某个人” 摄像头照片

    仅用来学习,希望给你们有提供到学习上的作用. 1.安装库 需要安装python3.5以上版本,在官网下载即可.然后安装库opencv-python,安装方式为打开终端输入命令行. 2.更改收件人和发件 ...

  3. php 实现字符串最大子串长度

    求字符串最大子串长度<?php class zif { public function sz($str) { $strsz = str_split($str); $zi = []; $len = ...

  4. JMeter脚本开发

    什么是jmeter脚本 用户操作系统的动作流程 用户操作系统的请求 类似演戏的剧本 怎么快速开发漂亮的jmeter脚本 准确 快速 漂亮,脚本逻辑清晰,维护性高 脚本开发方案 代理 http代理服务器 ...

  5. c++ 的学习笔记 第一集cim cout

    1. 你要用这个东西,所以得有包含它得头文件,就像java 你要用某个模块,你得包含这个模块 模块化??单片机里面学的模块化(可以在vs里面实现) 2. 当我把注册表regedit 程序删除之后成功了 ...

  6. P4100-[HEOI2013]钙铁锌硒维生素【矩阵求逆,最大匹配】

    正题 题目链接:https://www.luogu.com.cn/problem/P4100 题目大意 给出\(n\)个线性无关的向量\(A_i\),然后给出\(n\)个向量\(B_i\),求一个字典 ...

  7. P2150-[NOI2015]寿司晚宴【dp】

    正题 题目链接:https://www.luogu.com.cn/problem/P2150 题目大意 将\(2\sim n\)选出一些分成两个集合,要求这两个集合中没有一对数不是互质的.求方案数对\ ...

  8. Social Networ

    http://hansheng.xiong99.com.cn/ Paper:Dynamic Networks in Large Financial and Economic Systems

  9. Redis三种集群模式介绍

    三种集群模式 redis有三种集群模式,其中主从是最常见的模式. Sentinel 哨兵模式是为了弥补主从复制集群中主机宕机后,主备切换的复杂性而演变出来的.哨兵顾名思义,就是用来监控的,主要作用就是 ...

  10. 【Azure Developer】Azure Automation 自动化账号生成的时候怎么生成连接 与证书 (Connection & Certificate)

    Azure Automation :The Azure Automation service provides a highly reliable and scalable workflow exec ...