You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Springdoc中移除或隐藏Swagger UI的服务器下拉列表?

如何禁用/隐藏Swagger UI中的「Servers」下拉菜单

Swagger UI服务器下拉框

针对你使用的springdoc-openapi-ui:1.6.13,以下是几种可行的解决方案:

方案1:配置文件直接控制UI显示

在application.properties或application.yml中添加配置项,直接隐藏Servers模块:

  • properties格式:
springdoc.swagger-ui.show-servers=false
  • yml格式:
springdoc:
  swagger-ui:
    show-servers: false

方案2:通过OpenAPI配置清空服务器列表

创建配置类,自定义OpenAPI实例并清空servers集合,Swagger UI因无服务器数据会自动隐藏下拉菜单:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.swagger.v3.oas.models.OpenAPI;

@Configuration
public class OpenApiConfig {
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .servers(java.util.Collections.emptyList());
    }
}

方案3:自定义CSS隐藏(兜底方案)

如果前两种方案不生效,可通过自定义CSS强制隐藏Servers区域:

  1. 在src/main/resources/static目录下创建swagger-custom.css文件,内容如下:
.servers-wrapper {
    display: none !important;
}
  1. 在配置文件中指定自定义CSS路径:
  • properties格式:
springdoc.swagger-ui.css-url=/swagger-custom.css
  • yml格式:
springdoc:
  swagger-ui:
    css-url: /swagger-custom.css

内容的提问来源于stack exchange,提问作者Rohit M L

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 11:50:32