---
title: "用 Spring Cloud Alibaba 搭一套可跑的微服务：2026稳定版组合与落地步骤 - Angryecho"
description: "面向要在本地把注册发现、配置中心、网关、限流和分布式事务串起来的后端同学。本稿按掘金公开教程《Spring Cloud 微服务完整教程（2026版）》整理可复现步骤，技术栈以 Spring Cloud Alibaba 为主。["
canonical_url: "https://www.angryecho.com/c/wei_fu_wu/p/P2TBBoggpdt9g5Ffayhvb"
meta:
  "og:description": "面向要在本地把注册发现、配置中心、网关、限流和分布式事务串起来的后端同学。本稿按掘金公开教程《Spring Cloud 微服务完整教程（2026版）》整理可复现步骤，技术栈以 Spring Cloud Alibaba 为主。["
  "og:image": "https://www.angryecho.com/_og/d/c_Post%2Ctitle_~5ZCQ5qe9572R%2Cdescription_~5ZCQ5qe95LiA5LiL77yM5bCx5LiK5ZCQ5qe9572R44CC%2CpostId_P2TBBoggpdt9g5Ffayhvb%2Crevision_~MjAyNi0xMS0wMVQwMjo1NTo1Ny40MDAxNzda%2Cp_Ii9jL3dlaV9mdV93dS9wL1AyVEJCb2dncGR0OWc1RmZheWh2YiI%2Cs_6SZwU327bwq300CH.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "用 Spring Cloud Alibaba 搭一套可跑的微服务：2026稳定版组合与落地步骤"
---

> Index of every page on this site: [llms.txt](https://www.angryecho.com/llms.txt)

# **用 Spring Cloud Alibaba 搭一套可跑的微服务：2026稳定版组合与落地步骤**

面向要在本地把注册发现、配置中心、网关、限流和分布式事务串起来的后端同学。本稿按掘金公开教程《Spring Cloud 微服务完整教程（2026版）》整理可复现步骤，技术栈以 **Spring Cloud Alibaba** 为主。\[1]

## 准备工作

推荐版本组合（教程标注为2026生产稳定向）：

| 组件 | 版本 |
| --- | --- |
| JDK | 17 / 21 LTS |
| Spring Boot | 3.2.5 |
| Spring Cloud | 2023.0.2 (Leyton) |
| Spring Cloud Alibaba | 2023.0.1.2 |
| Nacos | 2.3.0 |
| Sentinel | 1.8.7 |
| Seata | 2.0.0 |
| Gateway | 4.1.0 |

对应关系：Spring Cloud Alibaba 2023.0.1.x → Spring Cloud 2023.0.x → Spring Boot 3.2.x。\[1]

先建空 Maven 父工程 `springcloud-demo`（packaging=pom），在 `dependencyManagement` 中 import 上述 BOM，子模块不再各自写版本号。

## 操作步骤

### 1、启动 Nacos

下载 Nacos 2.3.0，单机模式启动：`sh bin/startup.sh -m standalone`（Windows 用 `startup.cmd`）。浏览器打开 `http://localhost:8848/nacos`，默认账号密码均为 `nacos`。确认控制台能登录，再继续建服务。\[1]

### 2、搭建服务提供者并注册

新建子模块 `provider-service`，引入 `spring-boot-starter-web` 与 `spring-cloud-starter-alibaba-nacos-discovery`。`application.yml` 示例：

```yaml
server:
  port: 8001
spring:
  application:
    name: provider-service
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        namespace: public
        group: DEFAULT_GROUP
```

启动类加 `@SpringBootApplication`（`@EnableDiscoveryClient` 在较新版本可省略）。提供 `/provider/hello` 接口后启动，在 Nacos「服务列表」应能看到 `provider-service`。\[1]

### 3、搭建消费者：RestTemplate 或 OpenFeign

消费者端口可用 8080，同样接入 Nacos。用 RestTemplate 时加 `@LoadBalanced`，请求 URL 写服务名：`http://provider-service/provider/hello`。或改用 OpenFeign：引入 `spring-cloud-starter-openfeign`，启动类 `@EnableFeignClients`，接口上 `@FeignClient("provider-service")`。访问消费者接口能返回提供者文案，即负载调用打通。\[1]

### 4、接入 Nacos 配置中心

引入 `spring-cloud-starter-alibaba-nacos-config`；Spring Boot 3.x 还需 `spring-cloud-starter-bootstrap`。在 `bootstrap.yml` 配置 `server-addr`、`file-extension: yaml`。于控制台新建 Data ID=`provider-service.yaml`，用 `@Value` + `@RefreshScope` 读取。改配置并发布后，不重启应能读到新值。\[1]

### 5、加 Gateway 统一入口

新建 `gateway-service`（如端口9000），依赖 Gateway + Nacos Discovery。路由用 `uri: lb://provider-service`，`Path` 断言匹配后转发。确认直连提供者与经网关访问都能通。\[1]

### 6、Sentinel 限流与 Feign 降级（可选进阶）

引入 `spring-cloud-starter-alibaba-sentinel`，配置 dashboard 地址。控制台对接口设 QPS 限流后，超限应看到 Sentinel 拦截。若用 Feign，打开 `feign.sentinel.enabled=true` 并配置 fallback 类。\[1]

### 7、Seata AT 分布式事务（可选）

业务库建 `undo_log` 表，服务引入 Seata starter，注册到 Nacos；发起方方法加 `@GlobalTransactional`。任意分支异常应触发全局回滚。此步依赖 Seata Server 与多库环境，没有多服务写库场景可先跳过。\[1]

学习顺序上，建议先打通「Nacos注册 + 一次远程调用 + Gateway」，再加配置中心与 Sentinel；Seata 放到最后，因为要额外的 Server 与 undo\_log。这样每一步都有可观察的成功信号（服务出现在控制台、浏览器打到返回值、超限被拦截），排错成本更低。

## 注意事项

- 版本必须按 BOM 对齐，混用 Boot 2.x / Cloud 2021 线容易踩兼容坑。
- 配置中心在 Boot 3 默认不加载 bootstrap，漏加 starter 会表现为「读不到远程配置」。
- 网关 `StripPrefix` 与路径断言要一起核对，否则容易 404。
- 教程中的端口、账号为本地演示默认值，上线请改密钥与命名空间隔离。

> 以下步骤基于掘金2026版公开教程整理，于2026年10月27日对照原文核实；组件小版本请以官方发布说明为准。

## 来源

> \[1] [掘金《一份不可多得的〈微服务〉教程：Spring Cloud 微服务完整教程（2026版）》](https://juejin.cn/post/7654140424870576178)，2026年6月23日。

#微服务 #SpringCloudAlibaba #Nacos #Gateway #Sentinel #Seata

排序方式 :

### **成为第一条评论！**

Nobody's responded to this post yet. Add your thoughts and get the conversation going.

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://www.angryecho.com/c/wei_fu_wu/p/P2TBBoggpdt9g5Ffayhvb#post","@type":"DiscussionForumPosting","commentCount":0,"dateModified":"2026-11-01T02:55:57.400Z","datePublished":"2026-06-23T04:00:00.000Z","description":"面向要在本地把注册发现、配置中心、网关、限流和分布式事务串起来的后端同学。本稿按掘金公开教程《Spring Cloud 微服务完整教程（2026版）》整理可复现步骤，技术栈以 Spring Cloud Alibaba 为主。[","headline":"用 Spring Cloud Alibaba 搭一套可跑的微服务：2026稳定版组合与落地步骤","isPartOf":"https://www.angryecho.com/c/wei_fu_wu","mainEntityOfPage":"https://www.angryecho.com/c/wei_fu_wu/p/P2TBBoggpdt9g5Ffayhvb","text":"面向要在本地把注册发现、配置中心、网关、限流和分布式事务串起来的后端同学。本稿按掘金公开教程《Spring Cloud 微服务完整教程（2026版）》整理可复现步骤，技术栈以 Spring Cloud Alibaba 为主。[1]\n\n准备工作\n\n推荐版本组合（教程标注为2026生产稳定向）：\n\n\n\n\n\n\n\n组件\n\n\n\n版本\n\n\n\n\n\nJDK\n\n\n\n17 / 21 LTS\n\n\n\n\n\nSpring Boot\n\n\n\n3.2.5\n\n\n\n\n\nSpring Cloud\n\n\n\n2023.0.2 (Leyton)\n\n\n\n\n\nSpring Cloud Alibaba\n\n\n\n2023.0.1.2\n\n\n\n\n\nNacos\n\n\n\n2.3.0\n\n\n\n\n\nSentinel\n\n\n\n1.8.7\n\n\n\n\n\nSeata\n\n\n\n2.0.0\n\n\n\n\n\nGateway\n\n\n\n4.1.0\n\n对应关系：Spring Cloud Alibaba 2023.0.1.x → Spring Cloud 2023.0.x → Spring Boot 3.2.x。[1]\n\n先建空 Maven 父工程 springcloud-demo（packaging=pom），在 dependencyManagement 中 import 上述 BOM，子模块不再各自写版本号。\n\n操作步骤\n\n1、启动 Nacos\n\n下载 Nacos 2.3.0，单机模式启动：sh bin/startup.sh -m standalone（Windows 用 startup.cmd）。浏览器打开 http://localhost:8848/nacos，默认账号密码均为 nacos。确认控制台能登录，再继续建服务。[1]\n\n2、搭建服务提供者并注册\n\n新建子模块 provider-service，引入 spring-boot-starter-web 与 spring-cloud-starter-alibaba-nacos-discovery。application.yml 示例：\n\nserver:\n  port: 8001\nspring:\n  application:\n    name: provider-service\n  cloud:\n    nacos:\n      discovery:\n        server-addr: 127.0.0.1:8848\n        namespace: public\n        group: DEFAULT_GROUP\n\n启动类加 @SpringBootApplication（@EnableDiscoveryClient 在较新版本可省略）。提供 /provider/hello 接口后启动，在 Nacos「服务列表」应能看到 provider-service。[1]\n\n3、搭建消费者：RestTemplate 或 OpenFeign\n\n消费者端口可用 8080，同样接入 Nacos。用 RestTemplate 时加 @LoadBalanced，请求 URL 写服务名：http://provider-service/provider/hello。或改用 OpenFeign：引入 spring-cloud-starter-openfeign，启动类 @EnableFeignClients，接口上 @FeignClient(\"provider-service\")。访问消费者接口能返回提供者文案，即负载调用打通。[1]\n\n4、接入 Nacos 配置中心\n\n引入 spring-cloud-starter-alibaba-nacos-config；Spring Boot 3.x 还需 spring-cloud-starter-bootstrap。在 bootstrap.yml 配置 server-addr、file-extension: yaml。于控制台新建 Data ID=provider-service.yaml，用 @Value + @RefreshScope 读取。改配置并发布后，不重启应能读到新值。[1]\n\n5、加 Gateway 统一入口\n\n新建 gateway-service（如端口9000），依赖 Gateway + Nacos Discovery。路由用 uri: lb://provider-service，Path 断言匹配后转发。确认直连提供者与经网关访问都能通。[1]\n\n6、Sentinel 限流与 Feign 降级（可选进阶）\n\n引入 spring-cloud-starter-alibaba-sentinel，配置 dashboard 地址。控制台对接口设 QPS 限流后，超限应看到 Sentinel 拦截。若用 Feign，打开 feign.sentinel.enabled=true 并配置 fallback 类。[1]\n\n7、Seata AT 分布式事务（可选）\n\n业务库建 undo_log 表，服务引入 Seata starter，注册到 Nacos；发起方方法加 @GlobalTransactional。任意分支异常应触发全局回滚。此步依赖 Seata Server 与多库环境，没有多服务写库场景可先跳过。[1]\n\n学习顺序上，建议先打通「Nacos注册 + 一次远程调用 + Gateway」，再加配置中心与 Sentinel；Seata 放到最后，因为要额外的 Server 与 undo_log。这样每一步都有可观察的成功信号（服务出现在控制台、浏览器打到返回值、超限被拦截），排错成本更低。\n\n注意事项\n\n\n\n\n\n版本必须按 BOM 对齐，混用 Boot 2.x / Cloud 2021 线容易踩兼容坑。\n\n\n\n配置中心在 Boot 3 默认不加载 bootstrap，漏加 starter 会表现为「读不到远程配置」。\n\n\n\n网关 StripPrefix 与路径断言要一起核对，否则容易 404。\n\n\n\n教程中的端口、账号为本地演示默认值，上线请改密钥与命名空间隔离。\n\n\n\n以下步骤基于掘金2026版公开教程整理，于2026年10月27日对照原文核实；组件小版本请以官方发布说明为准。\n\n来源\n\n\n\n[1] 掘金《一份不可多得的〈微服务〉教程：Spring Cloud 微服务完整教程（2026版）》，2026年6月23日。\n\n#微服务 #SpringCloudAlibaba #Nacos #Gateway #Sentinel #Seata","url":"https://www.angryecho.com/c/wei_fu_wu/p/P2TBBoggpdt9g5Ffayhvb","author":{"@type":"Person","name":"PhantomAlan","url":"https://www.angryecho.com/u/V2XPhantomAlan"},"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":0},{"@type":"InteractionCounter","interactionType":"https://schema.org/DislikeAction","userInteractionCount":0},{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":0},{"@type":"InteractionCounter","interactionType":"https://schema.org/ShareAction","userInteractionCount":0}]}]}
```

## Sitemap

See the full [sitemap](https://www.angryecho.com/sitemap.md) for all pages.
