在 Linux 上排查 Swagger 报错,可以按下面思路一步步来,先定位是「起不来」「访问不了」还是「接口文档异常」。
不同技术栈排查方式不同:
你可以先告诉我用的是哪种。
ps -ef | grep java
# 或
ps -ef | grep node
端口是否监听:
netstat -tunlp | grep 8080
# 或
ss -tunlp | grep 8080
curl http://localhost:8080/swagger-ui.html
curl http://localhost:8080/v3/api-docs
tail -f logs/application.log
常见错误:
Failed to start bean 'documentationPluginsBootstrapper'journalctl -u your-node-service
# 或直接看启动终端输出
1. Spring Boot 2.6+ 与 Swagger 冲突
spring:
mvc:
pathmatch:
matching-strategy: ANT_PATH_MATCHER
2. SpringDoc 推荐配置
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.x</version>
</dependency>
访问:
/swagger-ui/index.html
需要放行:
location /swagger-ui/ {
proxy_pass http://backend/;
}
location /v3/api-docs/ {
proxy_pass http://backend/;
}
firewall-cmd --list-all
firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload
请把下面信息贴出来:
我可以直接帮你定位到具体原因 ✅