更改位置以在Spring中调用swagger-ui [英] Change location to call swagger-ui in Spring
本文介绍了更改位置以在Spring中调用swagger-ui的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改位置以将swagger api文档从http://localhost:8081/swagger-ui.html
更改为http://localhost:8081/my-api-doc
?
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);
}
这篇关于更改位置以在Spring中调用swagger-ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文