【问题标题】:How to change Swagger-ui URL?如何更改 Swagger-ui URL?
【发布时间】:2016-11-25 09:17:29
【问题描述】:

我试图更改招摇网址,现在我有“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>

有人可以帮忙吗?

【问题讨论】:

  • 我们无法访问您的本地主机站点,因此您应该添加一些屏幕截图
  • @Polarbear0106 问题是我如何在 springfox 中将该 URL 更改为 localhost:8080/swagger

标签: swagger-ui


【解决方案1】:

您尝试过路径提供程序吗?

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

【讨论】:

  • 这对我不起作用,我在 localhost:8080/swagger 上看不到 Swagger UI
猜你喜欢
  • 2018-11-15
  • 2017-01-27
  • 2020-05-20
  • 1970-01-01
  • 2017-12-11
  • 2016-07-18
  • 1970-01-01
  • 2019-02-18
  • 2016-08-24
相关资源
最近更新 更多