快速入门
单体 Web 应用
Web 应用快速入门(starter-web-example)。
Nebula Starter Web Example
使用
nebula-starter-web的最简 Web 应用示例
功能特性
- 基于
nebula-starter-web,开箱即用 - 统一响应格式(
Result<T>) - 内置健康检查、性能监控端点
- JWT 安全认证(已配置开发密钥)
- 示例不使用数据库和缓存,已显式关闭对应 Starter 默认模块
项目结构
starter-web-example/
├── pom.xml
└── src/main/
├── java/io/nebula/examples/web/
│ ├── WebApplication.java # 启动类
│ └── controller/
│ └── HelloController.java # 示例控制器
└── resources/
└── application.yml # 应用配置
前置条件
- JDK 21+
- Maven 3.8+
- 无外部依赖
快速开始
# 1. 安装框架到本地仓库(首次需要)
cd /path/to/nebula
mvn install -DskipTests
# 2. 启动应用(端口 8080)
mvn -q -f examples/starter-web-example spring-boot:run
接口测试
# Hello 接口
curl http://localhost:8080/hello
# 响应: {"success":true,"code":"SUCCESS","message":"操作成功","data":"Hello, Nebula Web","timestamp":...}
# 健康检查
curl http://localhost:8080/health/ping
配置说明
server:
port: 8080
nebula:
web:
performance:
enabled: true # 启用性能监控
security:
jwt:
secret: ${JWT_SECRET:nebula-starter-web-example-dev-secret-key-at-least-32-bytes}
expiration: 86400 # Token 过期时间(秒)
data:
persistence:
enabled: false # 示例无数据库依赖
cache:
enabled: false # 示例无 Redis 依赖
E2E 验证
E2E_MODE=full E2E_WITH_MIDDLEWARE=false \
E2E_ONLY=starter-web-example examples/e2e-all.sh
核心代码
@RestController
public class HelloController {
@GetMapping("/hello")
public Result<String> hello() {
return Result.success("Hello, Nebula Web");
}
}