繁体   English   中英

如何更改Swagger-ui URL?

[英]How to change Swagger-ui URL?

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

    <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>

有人可以帮忙吗?

您是否尝试过路径提供程序?

    @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();
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM