如何更改 Swagger-ui URL? [英] How to change Swagger-ui URL?

查看:93
本文介绍了如何更改 Swagger-ui URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试更改 swagger URL,现在我有http://localhost:8080/context-root/rest/swagger-ui.html", 我希望它是 "http://localhost:8080/swagger".我尝试使用 DOCKET.Host("swagger"),但浏览器正在旋转.它没有加载屏幕.

I have tried to change the swagger URL, right now i have "http://localhost:8080/context-root/rest/swagger-ui.html", i want it to be "http://localhost:8080/swagger". I tried using the DOCKET.Host("swagger"), but browser is spinning. And its not loading screen.

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>

有人可以帮忙吗?

推荐答案

您是否尝试过 Path Provider ?

Have you tried Path Provider ?

    @Configuration
    @EnableSwagger2
    @Profile({"!production"})   
     public class SwaggerConfiguration extends WebMvcConfigurerAdapter {


        @Autowired
        private ServletContext servletContext;

        @Bean
        public Docket api() {

            return new Docket(DocumentationType.SWAGGER_2)
                    .host("localhost")
                    .pathProvider(new RelativePathProvider(servletContext) {
                        @Override
                        public String getApplicationBasePath() {
                            return "/swagger";
                        }
                    })
                    .protocols(new HashSet<String>(Arrays.asList(protocols)))
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build();
        }
    }

这篇关于如何更改 Swagger-ui URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆