本文介绍了如何更改Swagger-ui URL前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Spring Boot 1.5.9中使用Springfox Swagger2.
I am using Springfox Swagger2 with Spring boot 1.5.9.
我可以在此链接上访问swagger UI.
I can access swagger UI on this link.
http://localhost:8090/swagger-ui.html
如何将其更改为可在以下URL上使用?
How can I change it to be available on following URL?
http://localhost:8090/my/custom/path/swagger-ui.html
@EnableSwagger2
public class Configuration {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("my.favorite.package"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo()).useDefaultResponseMessages(false);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("My title").version("1.0")
.contact(new Contact("Blah", "blah.com", "blah@blah.com")).build();
}
}
推荐答案
尝试此配置类.
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select().apis(RequestHandlerSelectors.basePackage(""my.favorite.package""))
.paths(regex(PathSelectors.any()))
.build();
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs").setKeepQueryParams(true);
registry.addRedirectViewController("/documentation/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
registry.addRedirectViewController("/documentation/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
registry.addRedirectViewController("/documentation/swagger-resources", "/swagger-resources");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/documentation/**").addResourceLocations("classpath:/META-INF/resources/");
}
}
这篇关于如何更改Swagger-ui URL前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!