Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
full-statck-skills avatar

Spring Cloud Alibaba

  • 21 installs
  • 2 repo stars
  • Updated July 29, 2026
  • full-statck-skills/spring-skills

Guides building microservices with Spring Cloud Alibaba components: Nacos, Sentinel, RocketMQ, and Seata.

About

Provides Spring Cloud Alibaba guidance for Nacos discovery and config, Sentinel flow control, RocketMQ messaging, and Seata transactions. A developer uses it to build microservices on the Alibaba stack.

  • Nacos service registration and config center
  • Sentinel flow control and RocketMQ messaging

Spring Cloud Alibaba by the numbers

  • 21 all-time installs (skills.sh)
  • Ranked #3,451 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/spring-skills --skill spring-cloud-alibaba

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs21
repo stars2
Last updatedJuly 29, 2026
Repositoryfull-statck-skills/spring-skills

What it does

Guides building microservices with Spring Cloud Alibaba components: Nacos, Sentinel, RocketMQ, and Seata.

Files

SKILL.mdMarkdownGitHub ↗

Spring Cloud Alibaba 开发指南

概述

Spring Cloud Alibaba 是阿里巴巴提供的微服务解决方案,提供了 Nacos(服务注册与配置)、Sentinel(流量控制)、RocketMQ(消息队列)、Seata(分布式事务)等组件。

核心组件

1. Nacos(服务注册与配置中心)

Nacos Server 安装

# 下载 Nacos
wget https://github.com/alibaba/nacos/releases/download/2.2.0/nacos-server-2.2.0.tar.gz

# 解压并启动
tar -xzf nacos-server-2.2.0.tar.gz
cd nacos/bin
sh startup.sh -m standalone

服务注册

@SpringBootApplication
@EnableDiscoveryClient
public class UserServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(UserServiceApplication.class, args);
    }
}

application.yml

spring:
  application:
    name: user-service
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
        namespace: dev
        group: DEFAULT_GROUP

配置管理

spring:
  cloud:
    nacos:
      config:
        server-addr: localhost:8848
        file-extension: yaml
        namespace: dev
        group: DEFAULT_GROUP
        shared-configs:
          - data-id: common-config.yaml
            group: DEFAULT_GROUP
            refresh: true

动态配置刷新

@RestController
@RefreshScope
public class ConfigController {
    @Value("${app.name:default}")
    private String appName;
    
    @GetMapping("/config")
    public String getConfig() {
        return appName;
    }
}

2. Sentinel(流量控制)

依赖

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

配置

spring:
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080
        port: 8719
      datasource:
        flow:
          nacos:
            server-addr: localhost:8848
            dataId: ${spring.application.name}-flow-rules
            groupId: SENTINEL_GROUP
            rule-type: flow

流量控制

@Service
public class UserService {
    @SentinelResource(value = "getUser", blockHandler = "getUserBlockHandler")
    public User getUser(Long id) {
        return userRepository.findById(id)
            .orElseThrow(() -> new UserNotFoundException(id));
    }
    
    public User getUserBlockHandler(Long id, BlockException ex) {
        return new User(); // 降级处理
    }
}

熔断降级

@SentinelResource(
    value = "getUser",
    fallback = "getUserFallback",
    blockHandler = "getUserBlockHandler"
)
public User getUser(Long id) {
    // 业务逻辑
}

public User getUserFallback(Long id, Throwable ex) {
    // 降级处理
    return new User();
}

3. RocketMQ(消息队列)

依赖

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-rocketmq</artifactId>
</dependency>

配置

spring:
  cloud:
    stream:
      rocketmq:
        binder:
          name-server: localhost:9876
        bindings:
          output:
            producer:
              group: user-service-group

消息发送

@Service
public class UserService {
    private final RocketMQTemplate rocketMQTemplate;
    
    public UserService(RocketMQTemplate rocketMQTemplate) {
        this.rocketMQTemplate = rocketMQTemplate;
    }
    
    public void sendUserCreatedEvent(User user) {
        rocketMQTemplate.convertAndSend("user-topic", user);
    }
}

消息接收

@Component
@RocketMQMessageListener(
    topic = "user-topic",
    consumerGroup = "user-consumer-group"
)
public class UserEventListener implements RocketMQListener<User> {
    @Override
    public void onMessage(User user) {
        // 处理消息
        System.out.println("Received user: " + user.getName());
    }
}

4. Seata(分布式事务)

依赖

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>

配置

spring:
  cloud:
    alibaba:
      seata:
        tx-service-group: my-tx-group
        enabled: true

seata:
  enabled: true
  application-id: ${spring.application.name}
  tx-service-group: my-tx-group
  config:
    type: nacos
    nacos:
      server-addr: localhost:8848
      namespace: ""
      group: SEATA_GROUP
  registry:
    type: nacos
    nacos:
      server-addr: localhost:8848
      namespace: ""
      group: SEATA_GROUP

使用 @GlobalTransactional

@Service
public class OrderService {
    @GlobalTransactional
    public void createOrder(Order order) {
        // 1. 创建订单
        orderRepository.save(order);
        
        // 2. 扣减库存
        productService.reduceStock(order.getProductId(), order.getQuantity());
        
        // 3. 扣减余额
        accountService.deductBalance(order.getUserId(), order.getAmount());
    }
}

5. Dubbo(RPC 框架)

依赖

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>

配置

spring:
  cloud:
    dubbo:
      application:
        name: user-service
      registry:
        address: nacos://localhost:8848
      protocol:
        name: dubbo
        port: 20880

服务提供者

@Service
@org.apache.dubbo.config.annotation.Service
public class UserServiceImpl implements UserService {
    public User getUser(Long id) {
        return userRepository.findById(id).orElseThrow();
    }
}

服务消费者

@Service
public class OrderService {
    @org.apache.dubbo.config.annotation.Reference
    private UserService userService;
    
    public Order createOrder(Long userId, Order order) {
        User user = userService.getUser(userId);
        // 创建订单逻辑
        return order;
    }
}

微服务架构示例

项目结构

microservices/
├── nacos-server/           # Nacos 服务
├── gateway/                # API 网关
├── user-service/           # 用户服务
├── order-service/          # 订单服务
└── product-service/        # 商品服务

配置示例

统一配置管理

# Nacos 配置中心
spring:
  cloud:
    nacos:
      config:
        server-addr: localhost:8848
        file-extension: yaml
        namespace: ${spring.profiles.active}
        group: DEFAULT_GROUP
        extension-configs:
          - data-id: common-datasource.yaml
            group: DEFAULT_GROUP
            refresh: true
          - data-id: common-redis.yaml
            group: DEFAULT_GROUP
            refresh: true

最佳实践

1. 服务注册

  • 使用 Nacos 作为服务注册中心
  • 配置合适的命名空间和分组
  • 设置健康检查

2. 配置管理

  • 使用 Nacos 配置中心统一管理
  • 区分环境配置(dev、test、prod)
  • 支持动态刷新

3. 流量控制

  • 使用 Sentinel 进行流量控制
  • 配置限流、熔断、降级规则
  • 监控服务调用情况

4. 分布式事务

  • 使用 Seata 处理分布式事务
  • 合理使用 @GlobalTransactional
  • 避免长事务

常用依赖

<!-- Nacos Discovery -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

<!-- Nacos Config -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

<!-- Sentinel -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

<!-- RocketMQ -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-rocketmq</artifactId>
</dependency>

<!-- Seata -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>

示例 Prompt

  • "如何使用 Spring Cloud Alibaba 构建微服务架构?"
  • "Nacos 如何配置服务注册和配置管理?"
  • "如何在 Spring Cloud Alibaba 中使用 Sentinel 进行流量控制?"
  • "Spring Cloud Alibaba 中如何使用 Seata 处理分布式事务?"
  • "如何配置 RocketMQ 消息队列?"

能力边界

✅ 适用场景

  • 当你需要使用此技能对应的技术栈时
  • 当项目需要遵循最佳实践时
  • 当需要快速上手或深入理解核心概念时

⚠️ 需要注意

  • 复杂业务逻辑需要结合具体场景调整
  • 性能优化需要根据实际数据量评估

❌ 不适用场景

  • 不相关的技术栈或框架
  • 需要完全自定义的特殊场景

常见陷阱 (Gotchas)

1. 版本兼容性:注意框架版本与依赖库的兼容性,不同版本 API 可能有差异 2. 配置文件格式:配置文件格式错误是最常见的问题,建议使用编辑器的语法检查 3. 环境变量:确保所有必要的环境变量已正确设置,敏感信息不要硬编码 4. 依赖冲突:多版本共存时注意依赖冲突,使用 lock 文件锁定版本 5. 性能陷阱:大数据量场景下注意性能优化,避免 N+1 查询等常见问题

使用流程

Step 1: 环境准备

确保开发环境已安装必要的依赖和工具。

Step 2: 配置初始化

根据项目需求进行基础配置。

Step 3: 核心功能使用

按照示例代码实现核心功能。

Step 4: 测试验证

运行测试确保功能正常。

Step 5: 部署上线

完成开发后进行部署和监控。

Related skills

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.