基于 Spring Cloud 微服务架构 + Vue 3 前后端分离的后台管理系统,用于个人学习和实践微服务相关技术,后续将接入 Spring AI 等 AI 能力。
| 层级 | 技术 | 版本 |
|---|---|---|
| 前端 | Vue 3 + Vite + TypeScript | 3.5 / 7 |
| 前端 UI | Element Plus + Tailwind CSS | 2.11 / 4.1 |
| 前端模板 | vue-pure-admin (精简版 thin) | v6.3.0 |
| 后端基础 | Spring Boot | 3.3.9 |
| 微服务 | Spring Cloud | 2023.0.4 (Leyton) |
| 服务发现/配置 | Nacos | 2.3.2 (单机模式) |
| 网关 | Spring Cloud Gateway | — |
| 认证鉴权 | Spring Security + JWT (HS256) | — |
| ORM | MyBatis-Plus (预留) | 3.5.9 |
| 数据库 | PostgreSQL 17 | — |
| 缓存 | Redis 7.x | — |
| AI (预留) | Spring AI | — |
┌─────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Browser │───▶│ Gateway (:8080) │───▶│ Auth (:8081) │───▶ PostgreSQL / Redis
└─────────┘ │ JWT 认证过滤 │ │ 登录/登出/刷新 │
│ CORS │ └──────────────────┘
│ 路由转发 │───▶┌──────────────────┐
└──────────────────┘ │ Admin (:8082) │───▶ PostgreSQL / Redis
│ 用户/角色/权限 │
└──────────────────┘
Nacos (:8848) ── 注册中心 & 配置中心 (PostgreSQL 持久化)
统一版本管理,聚合子模块:common, gateway, auth, admin
- common-core: 统一响应格式
Result<T>、常量、异常体系、通用工具 - common-security: JWT 工具类、用户上下文
UserContext(ThreadLocal)、LoginUser模型 - common-mybatis: MyBatis-Plus 配置(预留)
- 路由转发:
/auth/**→ auth 服务,/api/**→ admin 服务 - 全局认证 Filter:校验 JWT Token,白名单放行登录/刷新接口
- 通过 Header(X-User-Id, X-User-Name, X-User-Roles)透传用户信息到下游
- CORS 跨域配置
POST /auth/login— 用户名密码登录,返回 access_token + refresh_tokenPOST /auth/logout— 登出,Token 加入 Redis 黑名单POST /auth/refresh— 刷新令牌- 密码加密:BCrypt
- 当前为内存用户,后续接入数据库
GET /api/users— 用户列表(分页)GET /api/users/{id}— 用户详情UserContextFilter— 解析网关透传的 Header,注入线程上下文- 当前为内存数据,后续接入 MyBatis-Plus + PostgreSQL
- 前端 POST
/auth/login→ Gateway 路由到 Auth 服务 → 验证用户名密码 → 返回 JWT - 前端请求携带
Authorization: Bearer <token> - Gateway 全局 Filter 校验 JWT,将用户信息通过 Header 透传给下游
- 下游服务解析 Header 获取当前用户信息
- JDK 17+
- Maven 3.6+
- PostgreSQL 17(密码:
my990910MY@) - Redis 7.x(密码:
123456) - Node.js 20+
# 1. 创建数据库
psql -U postgres -c "CREATE DATABASE java_one;"
# 2. 导入表结构
psql -U postgres -d java_one -f docs/sql/nacos-schema.sql
psql -U postgres -d java_one -f docs/sql/fm-schema.sql
# 3. 启动 Nacos
docker compose up -d
# 4. 编译后端
cd backend
mvn clean install -DskipTests
# 5. 启动后端服务(三个终端分别执行)
mvn spring-boot:run -pl gateway
mvn spring-boot:run -pl auth
mvn spring-boot:run -pl admin
# 6. 启动前端
cd frontend
pnpm install
pnpm dev访问 http://localhost:8849,使用 admin / 123456 登录。
java-one/
├── backend/
│ ├── pom.xml # 父 POM,版本管理 + 模块聚合
│ ├── config/ # Nacos 集中配置(源码管理)
│ │ ├── common.yml # 共享配置:Redis、日志
│ │ ├── gateway.yml # 网关路由
│ │ ├── auth.yml # 认证服务端口、JWT 配置
│ │ └── admin.yml # 管理服务端口
│ ├── common/
│ │ ├── common-core/ # 公共核心:Result、异常、常量
│ │ ├── common-security/ # 公共安全:JWT、用户上下文
│ │ └── common-mybatis/ # MyBatis-Plus 配置(预留)
│ ├── gateway/ # Spring Cloud Gateway
│ ├── auth/ # 认证授权服务
│ └── admin/ # 后台管理服务
├── frontend/ # vue-pure-admin 前端
├── docs/
│ ├── sql/
│ │ ├── fm-schema.sql # 业务表结构(sys_user, sys_role 等)
│ │ └── nacos-schema.sql # Nacos PostgreSQL 表结构
│ └── superpowers/
│ ├── specs/ # 设计文档
│ └── plans/ # 实施计划
├── docker-compose.yml # Nacos 容器编排
├── .gitignore
└── README.md
仅供个人学习使用。