105 lines
2.5 KiB
Markdown
105 lines
2.5 KiB
Markdown
|
|
# 后端启动问题排查指南
|
|||
|
|
|
|||
|
|
## 问题:前端无法连接到后端 (ECONNREFUSED)
|
|||
|
|
|
|||
|
|
### 1. 检查后端服务是否启动
|
|||
|
|
|
|||
|
|
**方法1:检查端口占用**
|
|||
|
|
```bash
|
|||
|
|
netstat -ano | findstr :8082
|
|||
|
|
```
|
|||
|
|
如果没有任何输出,说明后端服务没有启动。
|
|||
|
|
|
|||
|
|
**方法2:访问后端接口**
|
|||
|
|
在浏览器访问:http://localhost:8082/api/product/1
|
|||
|
|
如果无法访问,说明后端服务没有启动。
|
|||
|
|
|
|||
|
|
### 2. 启动后端服务
|
|||
|
|
|
|||
|
|
#### 在 IDE 中启动(推荐)
|
|||
|
|
|
|||
|
|
1. 打开 `MTKJPAY/mt-pay` 项目
|
|||
|
|
2. 找到 `MtPayApplication.java` 文件
|
|||
|
|
3. 右键点击 → Run 'MtPayApplication.main()'
|
|||
|
|
4. 查看控制台输出,确认启动成功
|
|||
|
|
|
|||
|
|
#### 使用 Maven 命令启动
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd E:\MTKJPAY\mt-pay
|
|||
|
|
mvn clean spring-boot:run
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3. 常见启动失败原因
|
|||
|
|
|
|||
|
|
#### 问题1:Spring Boot 版本错误
|
|||
|
|
- **症状**:Maven 依赖下载失败,找不到 Spring Boot 4.0.0
|
|||
|
|
- **解决**:已修复为 Spring Boot 3.2.0
|
|||
|
|
|
|||
|
|
#### 问题2:数据库连接失败
|
|||
|
|
- **症状**:启动时报错 "Cannot create PoolableConnectionFactory"
|
|||
|
|
- **解决**:
|
|||
|
|
1. 检查 `application-dev.yml` 中的数据库配置
|
|||
|
|
2. 确认数据库服务是否运行
|
|||
|
|
3. 确认网络是否可以访问数据库服务器
|
|||
|
|
|
|||
|
|
#### 问题3:端口被占用
|
|||
|
|
- **症状**:启动时报错 "Port 8082 is already in use"
|
|||
|
|
- **解决**:
|
|||
|
|
1. 查找占用端口的进程:`netstat -ano | findstr :8082`
|
|||
|
|
2. 结束进程或修改端口配置
|
|||
|
|
|
|||
|
|
#### 问题4:依赖缺失
|
|||
|
|
- **症状**:编译错误或 ClassNotFoundException
|
|||
|
|
- **解决**:
|
|||
|
|
```bash
|
|||
|
|
cd E:\MTKJPAY\mt-pay
|
|||
|
|
mvn clean install
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 4. 验证启动成功
|
|||
|
|
|
|||
|
|
启动成功后,控制台应该显示:
|
|||
|
|
```
|
|||
|
|
========================================
|
|||
|
|
应用启动成功!
|
|||
|
|
========================================
|
|||
|
|
应用名称: mt-pay
|
|||
|
|
运行环境: dev
|
|||
|
|
访问地址: http://localhost:8082/
|
|||
|
|
========================================
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 5. 测试后端接口
|
|||
|
|
|
|||
|
|
启动成功后,测试接口:
|
|||
|
|
- 商品详情:http://localhost:8082/api/product/1
|
|||
|
|
- 图片上传:POST http://localhost:8082/api/product/upload/image
|
|||
|
|
|
|||
|
|
### 6. 检查日志
|
|||
|
|
|
|||
|
|
如果启动失败,查看日志文件:
|
|||
|
|
- 位置:`MTKJPAY/mt-pay/logs/` 目录
|
|||
|
|
- 或查看控制台输出的错误信息
|
|||
|
|
|
|||
|
|
## 快速诊断命令
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 1. 检查端口占用
|
|||
|
|
netstat -ano | findstr :8082
|
|||
|
|
|
|||
|
|
# 2. 检查 Java 进程
|
|||
|
|
jps -l | findstr mtpay
|
|||
|
|
|
|||
|
|
# 3. 测试后端接口(需要先安装 curl)
|
|||
|
|
curl http://localhost:8082/api/product/1
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 如果仍然无法启动
|
|||
|
|
|
|||
|
|
请提供以下信息:
|
|||
|
|
1. 启动时的完整错误日志
|
|||
|
|
2. IDE 控制台的错误信息
|
|||
|
|
3. Maven 构建输出(如果使用 Maven 启动)
|
|||
|
|
|