在 Debian 上“调试 Swagger”通常指下面几类场景之一,我先按常见情况给你一个清晰路线,你可以对照你的情况选择:
curl http://localhost:8080/v2/api-docs
# 或
curl http://localhost:8080/v3/api-docs
如果这里就报错,问题在后端,不是 UI。
journalctl -u your-service -f
# 或
docker logs -f container_name
常见错误:
No mapping for GET /v2/api-docsFailed to load API definitionNullPointerException in ModelConverters打开 Swagger UI → F12 → Network:
/v2/api-docs 状态码location /swagger-ui/ {
proxy_pass http://localhost:8080/;
}
✅ 正确示例(Spring Boot):
location /swagger-ui.html {
proxy_pass http://localhost:8080;
}
location /swagger-resources/ {
proxy_pass http://localhost:8080;
}
location /v2/api-docs {
proxy_pass http://localhost:8080;
}
location /webjars/ {
proxy_pass http://localhost:8080;
}
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
或(推荐):
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
@EnableSwagger2
@Configuration
public class SwaggerConfig {}
springdoc 不需要这个。
如果你用了 Spring Security:
.antMatchers(
"/swagger-ui.html",
"/swagger-resources/**",
"/v2/api-docs",
"/webjars/**"
).permitAll()
你可以直接贴:
我可以一步一步帮你调。