API 参考

使用指南-快速开始

「历史文档」使用指南中的快速开始内容。

快速开始

1. 添加自动配置依赖

<!-- 统一自动配置模块 -->
<dependency>
    <groupId>io.nebula</groupId>
    <artifactId>nebula-autoconfigure</artifactId>
    <version>2.0.1-SNAPSHOT</version>
</dependency>

<!-- 按需添加功能模块 -->
<dependency>
    <groupId>io.nebula</groupId>
    <artifactId>nebula-discovery-nacos</artifactId>
</dependency>
<dependency>
    <groupId>io.nebula</groupId>
    <artifactId>nebula-rpc-http</artifactId>
</dependency>
<dependency>
    <groupId>io.nebula</groupId>
    <artifactId>nebula-data-persistence</artifactId>
</dependency>
<!-- 其他模块... -->

2. 配置应用

注意:推荐使用 Starter 而非直接依赖 nebula-autoconfigure。各 Starter 已通过 NebulaStarterDefaultsPostProcessor 自动启用对应模块,无需重复声明 enabled: true。 以下示例适用于直接使用 nebula-autoconfigure 的场景。

spring:
  application:
    name: my-nebula-app

nebula:
  # 服务发现配置(Level 3,需显式启用)
  discovery:
    nacos:
      enabled: true
      server-addr: localhost:8848
      namespace: dev

  # RPC 配置(Level 3,需显式启用)
  rpc:
    http:
      enabled: true
    discovery:
      enabled: true

  # 数据访问配置(Level 2,需显式启用)
  data:
    persistence:
      enabled: true
    cache:
      enabled: true

3. 启动应用

所有配置的功能模块将自动初始化并可用。 如果使用 Starter(如 nebula-starter-service),其 nebula-defaults.properties 已默认启用对应模块,只需配置连接信息(server-addr 等)即可。