要更改Swagger UI的基本路径,您可以通过配置Swagger2来实现。以下是一般的步骤:
@Configuration
注解标记该类。pom.xml
文件中添加以下依赖:<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>
@EnableSwagger2
注解启用Swagger2,并创建一个Docket
bean来配置Swagger2的行为。在Docket
的构造函数中,您可以指定Swagger UI的基本路径。@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.pathMapping("/your-base-path") // 设置Swagger UI的基本路径
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.controller"))
.paths(PathSelectors.any())
.build();
}
}
在上述示例中,.pathMapping("/your-base-path")
指定了Swagger UI的基本路径。您可以将/your-base-path
替换为您想要的基本路径。
领取专属 10元无门槛券
手把手带您无忧上云