首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Spring Fox (Swagger-UI) 2.9.2如何禁用“试用”按钮

Spring Fox(Swagger-UI)是一个用于生成和展示API文档的开源工具。它可以帮助开发人员更好地理解和使用API,并提供了一个交互式的界面来测试API的各种功能。

要禁用Swagger-UI中的“试用”按钮,可以通过以下步骤实现:

  1. 在Spring Boot项目的pom.xml文件中,添加以下依赖项:
代码语言:txt
复制
<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>
  1. 创建一个Swagger配置类,例如SwaggerConfig.java,并添加以下内容:
代码语言:txt
复制
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .enableUrlTemplating(false); // 禁用试用按钮
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API文档")
                .description("这是一个示例API文档")
                .version("1.0.0")
                .build();
    }
}

在上述代码中,我们通过调用enableUrlTemplating(false)方法来禁用试用按钮。

  1. 运行Spring Boot应用程序,并访问Swagger-UI界面(通常是http://localhost:8080/swagger-ui.html)。

现在,你应该能够看到Swagger-UI界面,并且试用按钮已被禁用。

请注意,以上答案是基于Spring Fox(Swagger-UI)2.9.2版本的,如果你使用的是其他版本,可能会有一些差异。另外,腾讯云没有提供与Spring Fox(Swagger-UI)直接相关的产品或服务,因此无法提供相关的腾讯云产品链接。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券