# demo_springboot **Repository Path**: attacker/demo_springboot ## Basic Information - **Project Name**: demo_springboot - **Description**: java spring boot 测试jar - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-07 - **Last Updated**: 2025-12-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Demo SpringBoot 微服务项目 基于 Spring Boot + Nacos + Redis + MySQL 的微服务示例项目。 ## 🏗️ 架构说明 - **Spring Boot 2.7.18**: 微服务框架 - **Nacos**: 配置中心和服务发现 - **Redis**: 缓存服务 - **MySQL**: 数据存储 - **Kubernetes**: 容器编排部署 ## 🔑 登录账号 - **用户名**: `super123` - **密码**: `super@123` ## 🚀 Kubernetes 部署 ### 前置要求 - Kubernetes 集群 - Nacos 服务(配置中心) - MySQL 数据库 - Redis 服务 ### 1. 初始化数据库 ```bash mysql -h -u -p < deploy/init.sql ``` ### 2. 配置 Nacos 在 Nacos 控制台创建配置文件: - **Data ID**: `demo-springboot.yml` - **Group**: `DEFAULT_GROUP` - **命名空间**: `test` - **配置格式**: YAML 配置内容参考 `deploy/demo-springboot.yml`,修改以下配置: - MySQL 连接地址、数据库名、用户名、密码 - Redis 连接地址、密码(如无密码可注释掉 password 行) ### 3. 创建 Nacos 密码 Secret ```bash kubectl create secret generic nacos-passwd \ --from-literal=password=nacos \ -n test ``` ### 4. 部署后端服务 ```bash kubectl apply -f deploy/k8s-backend.yml ``` ### 5. 部署前端服务 ```bash kubectl apply -f deploy/k8s-frontend.yml ``` ### 6. 验证部署 ```bash # 查看后端 Pod 状态 kubectl get pods -n test -l app=demo-springboot # 查看前端 Pod 状态 kubectl get pods -n test # 查看服务 kubectl get svc -n test ``` ## 📝 本地开发 ### 环境要求 - JDK 17+ - Maven 3.8+ - MySQL 8.0+ - Redis 6.0+ - Node.js v16+ (前端) ### 启动步骤 1. **初始化数据库** ```bash mysql -h 127.0.0.1 -u root -p < deploy/init.sql ``` 2. **配置 Nacos** - 在 Nacos 控制台创建 `demo-springboot.yml` 配置文件 - 参考 `deploy/demo-springboot.yml` 修改数据库和 Redis 配置 3. **打包后端** ```bash ./build.sh ``` 4. **启动后端** ```bash ./start.sh ``` 5. **启动前端** ```bash cd ui && npm install && npm run dev ``` ### 访问地址 - **前端**: http://localhost:5174 - **后端**: http://localhost:9080 - **API文档**: http://localhost:9080/swagger-ui.html ## 📚 相关文档 - **Swagger UI**: http://localhost:9080/swagger-ui.html - **健康检查**: http://localhost:9080/actuator/health ## ⚙️ 配置说明 ### Nacos 配置 应用通过环境变量连接 Nacos: ```yaml nacos.config.server-addr: nacos.opsx.vip:8848 nacos.config.namespace: test nacos.config.username: nacos nacos.config.password: <从Secret读取> ``` ### 数据库配置 在 Nacos 配置中心设置 MySQL 连接信息,数据库名为 `bookdb`。 ### Redis 配置 在 Nacos 配置中心设置 Redis 连接信息,支持密码和无密码两种模式。