一个现代化的博客系统后端,基于Spring Boot 3.5.4构建,支持文章管理、用户认证、文件存储等核心功能。
- ✅ 文章CRUD操作(支持富文本编辑)
- ✅ 标签和分类管理
- ✅ 文章搜索与高级筛选
- ✅ 文章状态管理(草稿/发布/归档)
- ✅ JWT Token认证机制
- ✅ 角色权限控制(管理员/用户)
- ✅ 密码安全策略
- ✅ 接口访问频率限制
- ✅ 支持MinIO/RustFS对象存储
- ✅ 图片自动压缩和优化
- ✅ 未使用文件自动清理
- ✅ 文件访问权限控制
- ✅ Redis缓存加速
- ✅ 审计日志记录
- ✅ 健康监控检查
- ✅ 多环境配置支持
- ✅ Docker容器化部署
技术栈 | 版本 | 用途 |
---|---|---|
Spring Boot | 3.5.4 | 核心框架 |
Spring Security | 6.x | 安全认证 |
Spring Data JPA | 3.x | 数据访问 |
PostgreSQL | 17+ | 主数据库 |
Redis | 7.x | 缓存与会话 |
MinIO/RustFS | / | 文件存储 |
JWT | 0.12.3 | Token认证 |
MapStruct | 1.5.5 | 对象映射 |
OpenAPI | 2.8.9 | API文档 |
- Java 21+
- Maven 3.8+
- PostgreSQL 17+
- Redis 7+
- MinIO/RustFS
# 克隆项目
git clone <repository-url>
cd blog-backend-v3
# 启动依赖服务,新版为 RustFS
cd docker
docker-compose up -d postgres redis rustfs
# 启动依赖服务,旧版为 MinIO
cd docker
docker-compose up -d postgres redis minio
# 启动应用
./mvnw spring-boot:run
# 1. 配置数据库
# 创建PostgreSQL数据库: blog_db
# 2. 配置Redis
# 启动Redis服务
# 3. 配置文件存储
# 启动MinIO/RustFS服务
# 4. 启动应用
./mvnw spring-boot:run
- 应用地址: http://localhost:8880
- API文档: http://localhost:8880/swagger-ui.html
- 健康检查: http://localhost:8880/actuator/health
POST /api/auth/login
- 用户登录POST /api/auth/register
- 用户注册POST /api/auth/refresh
- Token刷新
GET /api/articles
- 获取文章列表POST /api/articles
- 创建文章GET /api/articles/{id}
- 获取文章详情PUT /api/articles/{id}
- 更新文章DELETE /api/articles/{id}
- 删除文章
POST /api/file/upload
- 文件上传DELETE /api/file/delete
- 文件删除
项目支持多环境配置:
application.yml
- 通用配置application-dev.yml
- 开发环境application-test.yml
- 测试环境application-prod.yml
- 生产环境
# 数据库配置
spring:
datasource:
url: jdbc:postgresql://localhost:5432/blog_db
username: postgres
password: your_password
# Redis配置
spring:
data:
redis:
host: localhost
port: 6379
password: your_redis_password
# 文件存储配置
app:
minio:
endpoint: http://localhost:9000
access-key: your_access_key
secret-key: your_secret_key
bucket: blog
# 构建镜像
./mvnw clean package
docker build -t blog-backend:v3 .
# 启动服务
docker-compose -f docker/docker-compose.yml up -d
- 应用健康: http://localhost:8880/actuator/health
- 数据库状态: http://localhost:8880/actuator/health/db
- Redis状态: http://localhost:8880/actuator/health/redis
- 文件存储状态: http://localhost:8880/actuator/health/minio
- Prometheus指标: http://localhost:8880/actuator/prometheus
- 应用指标: http://localhost:8880/actuator/metrics
# 运行单元测试
./mvnw test
# 运行集成测试
./mvnw verify
src/main/java/com/hqgis/blog/
├── article/ # 文章管理
├── audit/ # 审计日志
├── cache/ # 缓存管理
├── category/ # 分类管理
├── config/ # 系统配置
├── file/ # 文件管理
├── monitor/ # 监控管理
├── security/ # 安全认证
├── tag/ # 标签管理
├── user/ # 用户管理
└── properties/ # 配置属性
- Fork 项目
- 创建功能分支 (
git checkout -b feature/AmazingFeature
) - 提交更改 (
git commit -m 'Add some AmazingFeature'
) - 推送到分支 (
git push origin feature/AmazingFeature
) - 开启 Pull Request
本项目采用 Apache 2.0 许可证。
- Issues: 请通过GitHub Issues提交问题
- 文档: 查看 API文档
- 示例: 参考
docker/
目录下的配置示例