Linux环境下Swagger版本兼容性问题与解决方案
一 常见兼容性问题与根因
二 版本选择与迁移路径
三 快速排查清单
mvn dependency:tree或gradle dependencies,排查冲突依赖(重点关注Guava、Spring、Swagger/OpenAPI相关包),必要时用Maven Helper定位并排除冲突版本。四 配置示例
SpringFox Swagger 2 多分组共存
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
@Bean
public Docket v1Docket() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("v1")
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.v1"))
.paths(PathSelectors.ant("/api/v1/**"))
.build();
}
@Bean
public Docket v2Docket() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("v2")
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.v2"))
.paths(PathSelectors.ant("/api/v2/**"))
.build();
}
SpringDoc OpenAPI 3 单分组示例
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.14</version>
</dependency>
application.properties中配置springdoc.group-configs。五 部署与安全建议
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Forwarded-Prefix /api-docs;
}