学习篇:基于swagger2.7.0-集成springboot2.1.x

一、springBoot集成swagger

参看文档:https://springfox.github.io/springfox/docs/current/#springfox-swagger-ui

1. 集成方式
  • Maven集成

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

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


  • Gradle集成

repositories {

  jcenter()

}



dependencies {

    compile "io.springfox:springfox-swagger2:2.7.0"

    compile "io.springfox:springfox-swagger-ui:2.7.0"

}

2. 注入swagger配置bean

/**
 * @ClassName SwaggerConfig
 * @Description TODO
 * @Author eastern
 * @Date 2019/8/12 下午4:41
 * @Version 1.0
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket controllerApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("controller")
                .apiInfo(apiInfo())
                .select()
                // 只显示xx Controller下的api 包路径
                 .apis(RequestHandlerSelectors.basePackage(ProductController.class.getPackage().getName()))
                // 只显示以products开头的api
                // .paths(PathSelectors.ant("/products/*"))
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("HTTP API")
                .description("Swagger测试接口")
                .termsOfServiceUrl("http://springfox.io")
                .license("Apache License Version 2.0")
                .contact(new Contact("zhangsan", "", "xxxxxxx@qq.com"))
                .version("2.0")
                .build();
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要访问http://localhost:8080/swagger-ui/index.html,您需要先进行一些操作。首先,您可以使用克隆应用程序命令来获取swagger-ui-akka-http的项目源代码。命令如下:sbt new knoldus/swagger-ui-akka-http.g8,然后进入项目目录:cd swagger-ui-akka-http。 接下来,您需要编译应用程序。您可以使用以下命令进行编译:sbt clean compile。这将确保项目的代码编译正确。 一旦编译成功,您可以运行应用程序。使用sbt run命令来启动应用程序。这将使您能够在本地主机上的端口8080上访问应用程序的URI:localhost:8080/swagger-ui/index.html。 请注意,在访问URL时,有时会出现错误,例如"error parsing http request header"。如果您遇到此问题,请尝试登录的URL地址,并确保正确登录后再次尝试访问目标URL。 另外,请注意在URL的末尾添加"#/”,有时可能需要这样做。这可能是因为特定应用程序或网站的要求,用于正确导航到所需的资源或页面。所以,如果您遇到问题,请尝试在URL末尾添加"#/”。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [swagger-ui-akka-http.g8:使用Akka Http API生成Swagger UI](https://download.csdn.net/download/weixin_42143806/18703738)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Swagger登录地址(首次登录可能会报错)](https://blog.csdn.net/weixin_46213083/article/details/125167028)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值