在 Linux 下调试 Swagger 接口,常见有几种场景,下面按最常用 → 进阶给你一套完整实用的方案。
通常地址是:
http://localhost:端口/swagger
http://localhost:端口/swagger-ui.html
http://localhost:端口/swagger/index.html
例如:
http://127.0.0.1:8080/swagger
✅ 优点:不用额外工具,适合快速验证
❌ 缺点:不方便自动化
Swagger 本质上就是 HTTP 接口。
curl http://localhost:8080/v3/api-docs
或:
curl http://localhost:8080/v2/api-docs
curl "http://localhost:8080/api/user?id=1"
curl -X POST http://localhost:8080/api/user \
-H "Content-Type: application/json" \
-d '{"name":"tom","age":18}'
curl http://localhost:8080/api/user \
-H "Authorization: Bearer YOUR_TOKEN"
✅ 优点:Linux 服务器必会
✅ 适合 CI / 脚本 / 容器环境
sudo apt install swagger-codegen
swagger-codegen generate \
-i http://localhost:8080/v3/api-docs \
-l java \
-o ./client
支持语言:
✅ 适合:自动化测试 / 调用第三方接口
虽然你是在 Linux,但完全可以:
# 下载 Postman
wget https://dl.pstmn.io/download/latest/linux64
或直接用 Insomnia(轻量):
snap install insomnia
✅ 优点:
netstat -tunlp | grep 8080
# 或
ss -tunlp | grep 8080
sudo ufw status
sudo ufw allow 8080
curl http://localhost:8080/v3/api-docs
常见路径:
/v2/api-docs/v3/api-docs/swagger-resourceslogging:
level:
springfox: DEBUG
@EnableSwagger2
@SecurityScheme
| 场景 | 推荐方式 |
|---|---|
| 快速验证 | Swagger UI |
| Linux 服务器 | curl |
| 自动化 | swagger-codegen |
| 复杂接口 | Postman / Insomnia |
| 查问题 | curl + 日志 |
如果你愿意,可以告诉我:
我可以直接给你针对你项目的调试命令。