有几种方法可以禁用Swagger UI的加载:
- 在Swagger配置文件中,将
swagger-ui
的相关配置项设置为false。例如,在Spring Boot中,可以在application.yml
文件中添加以下内容:
springfox.swagger-ui.enabled: false
- 使用Swagger注解来禁用UI的加载。在代码中使用
@EnableSwagger2
注解时,可以将swagger-ui
的值设置为false。
@EnableSwagger2(swaggerUIEnabled = false)
- 如果使用的是Maven构建工具,可以在pom.xml文件中排除Swagger UI相关的依赖项。
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>{version}</version>
<exclusions>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
</exclusion>
</exclusions>
</dependency>