- 使用
springdoc-openapi时,将spring-boot-starter-web替换spring-boot-starter-webflux导致,此时可能忘记替换springdoc-openapi-starter-webflux-ui - 配置文件问题,检查
path是否正确配置 WebMvcConfigurer、WebFluxConfigurer配置问题- 是否有封装统一全局响应,没有排除swagger api,导致swagger ui api 获取的数据格式不正确。
- 浏览器缓存: 一定要强制刷新或者通过无痕浏览器访问配置更新后的swagger ui。
spring-boot-starter-web 替换 spring-boot-starter-webflux导致
spring-boot-starter-web对应使用springdoc-openapi-starter-webmvc-ui,spring-boot-starter-webflux对应使用springdoc-openapi-starter-webflux-ui,需要一起还
配置文件path正确配置
检查配置文件path是否正确
注:webmvc-ui会带有前缀,/swagger-ui,此时访问http://localhost:8080/swagger-ui/index.html#/,才是正确路径
webflux-ui会带有前缀,/webjars/swagger-ui,此时访问http://localhost:8080/webjars/swagger-ui/index.html#/,才是正确路径
springdoc:
api-docs:
enabled: true # 是否开启 OpenAPI JSON 接口
path: /v3/api-docs # 默认路径
swagger-ui:
enabled: true
path: /index.html # 自定义 Swagger UI 路径,访问此路径会重定向到/swagger-ui/index.html
disable-swagger-default-url: true # 禁用 swagger 默认自带的示例 ui
webjars:
prefix: # 禁用默认的 /webjars 路径,webflux 会访问到 /webjars/swagger-ui/index.html
WebMvcConfigurer、WebFluxConfigurer配置问题
检查是否实现WebMvcConfigurer,实现是否有问题,WebFluxConfigurer同理只是继承改成WebFluxConfigurer。
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}