在 Linux 下“调试 Swagger”通常指下面几种场景之一,我先按最常见情况给你一个清晰路径,你再对照自己的情况:
先确认你是哪一种:
Swagger UI 本质只是渲染一个 JSON:
curl http://localhost:8080/v3/api-docs
或:
curl http://localhost:8080/swagger-ui.html
✅ 如果 JSON 报错 → 问题在后端
✅ 如果 JSON 正常但页面异常 → 问题在前端
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
http://localhost:8080/swagger-ui.html
http://localhost:8080/v3/api-docs
# 看日志
tail -f logs/application.log
# 看端口
netstat -tunlp | grep 8080
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) {
http.authorizeHttpRequests()
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll();
}
curl -I http://localhost:8080/swagger-ui.html
检查:
用命令行校验:
npm install -g @apidevtools/swagger-cli
swagger-cli validate swagger.yaml
或在线:
https://editor.swagger.io
常见问题:
@RestController@RequestMapping开启 debug:
logging:
level:
org.springdoc: DEBUG
# 看端口
ss -tunlp | grep 8080
# 看进程
ps -ef | grep java
# 抓 HTTP 请求
tcpdump -i lo port 8080
# 测试接口
curl -X GET http://localhost:8080/v3/api-docs
你可以直接回复下面任意一条,我可以给你精确到命令级的方案:
我可以一步一步帮你排。