如何更改位置以调用 swagger api 文档从 http://localhost:8081/swagger-ui.html
到 http://localhost:8081/my-api-文档
?
How I can change location to call swagger api docs from http://localhost:8081/swagger-ui.html
to http://localhost:8081/my-api-doc
?
我的 SwaggerConfig 是
My SwaggerConfig is
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.package"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
我将 springfox-swagger2
和 springfox-swagger-ui
都与 version 2.7.0
一起使用.
And I use springfox-swagger2
and springfox-swagger-ui
both with version 2.7.0
.
如果使用 Spring Boot,可以添加一个映射来重定向请求,例如:
If using Spring Boot, you can add a mapping to redirect the request like:
@GetMapping("/swagger")
public void swaggerRedirect(HttpServletResponse response) {
response.setHeader("Location", "/swagger-ui.html");
response.setStatus(302);
}