【问题标题】:How to add /api before swagger-ui.html如何在 swagger-ui.html 之前添加 /api
【发布时间】:2019-09-09 23:22:24
【问题描述】:

如何在swagger-ui.html前添加默认参数

像这样:

http://localhost:8080/api/swagger-ui.html

到目前为止我已经集成的内容:

Pom.xml:

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

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

SwaggerConfig.java:

@Configuration
@EnableSwagger2
public class SwaggerConfig {                                    
    @Bean
    public Docket api() { 
        return new Docket(DocumentationType.SWAGGER_2)  
          .select()                                  
          .apis(RequestHandlerSelectors.any())              
          .paths(PathSelectors.any())                          
          .build();                                           
    }
}

Do I have to map "swagger-ui.html" to something with @RequestMapping?

【问题讨论】:

标签: spring-boot swagger-ui request-mapping


【解决方案1】:

试试这个:

new Docket(DocumentationType.SWAGGER_2)
    .host("www.mydomain.com")
    .pathProvider(new RelativePathProvider(servletContext) {
        @Override
        public String getApplicationBasePath() {
            return "/myapi";
        }
    });

如果您遇到任何问题:https://github.com/springfox/springfox/issues/1443

【讨论】:

  • 我可以直接在application.yml中添加server.servlet = /api吗?
【解决方案2】:

在 SwaggerConfig.java 中的类级别包含以下注释:

@PropertySource("classpath:swagger.properties") 和 @ComponentScan

然后在资源目录中创建swagger.properties文件(与你的application.properties文件相同的位置)

【讨论】:

    猜你喜欢
    • 2016-07-09
    • 2018-06-08
    • 2017-02-19
    • 1970-01-01
    • 2019-12-03
    • 2018-08-28
    • 1970-01-01
    • 2021-09-19
    • 2021-02-25
    相关资源
    最近更新 更多