当前位置: 首页 > news >正文

springboot 整合 swagger2

整合步骤

  1. pom 添加依赖
        <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>
  1. 创建 swagger 配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {private static ApiInfo DEFAULT = null;@Beanpublic Docket docket() {return new Docket(DocumentationType.SWAGGER_2);}
}
  1. 浏览器访问:http://localhost:8080/swagger-ui.html(注意端口号)

在这里插入图片描述

定制配置

修改页面内容

修改 SwaggerConfig.java

@Configuration
@EnableSwagger2
public class SwaggerConfig {private static ApiInfo DEFAULT = null;@Beanpublic Docket docket() {Docket docket = new Docket(DocumentationType.SWAGGER_2);ApiInfo apiInfo = new ApiInfoBuilder().contact(new Contact("Swagger - k8sclient","https://github.com/vazquez/k8sclient","vazquez@gmail.com")).title("Kubernetes Client API").description("This is a simple example of a Spring Boot RESTful service.").version("1.0").build();docket.apiInfo(apiInfo);return docket;}
}

浏览器访问:http://localhost:8080/swagger-ui.html

在这里插入图片描述

去掉 basic-error-controller

方法一:指定包显示

修改 SwaggerConfig

@Configuration
@EnableSwagger2
public class SwaggerConfig {private static ApiInfo DEFAULT = null;@Beanpublic Docket docket() {Docket docket = new Docket(DocumentationType.SWAGGER_2);ApiInfo apiInfo = new ApiInfoBuilder().title("Kubernetes Client API").description("This is a simple example of a Spring Boot RESTful service.").version("1.0").build();docket.apiInfo(apiInfo).select().apis(RequestHandlerSelectors.basePackage("com.vazquez.k8sclient.controller")).build();return docket;}
}

方法二:指定方法显示

修改 SwaggerConfig

@Configuration
@EnableSwagger2
public class SwaggerConfig {private static ApiInfo DEFAULT = null;@Beanpublic Docket docket() {Docket docket = new Docket(DocumentationType.SWAGGER_2);ApiInfo apiInfo = new ApiInfoBuilder().title("Kubernetes Client API").description("This is a simple example of a Spring Boot RESTful service.").version("1.0").build();docket.apiInfo(apiInfo).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).build();return docket;}
}

在 controller 类中方法,即接口方法上添加 @ApiOperation 注解(只有添加了 @ApiOperation 注解的方法才显示)

@ApiOperation(value = "获取集群下的所有事件", notes = "获取集群下的所有事件")@GetMappingpublic Response<ApiResponse<EventsV1EventList>> listNamespacedEvent(@PathVariable String clusterName, @PathVariable String namespaceName) {return eventService.listNamespacedEvent(clusterName, namespaceName);}

去掉 Models 中的非程序内容

http://www.lryc.cn/news/337447.html

相关文章:

  • redis-缓存穿透与雪崩
  • K8S临时存储-本地存储-PV和PVC的使用-动态存储(StorageClass)
  • jeecg-boot安装
  • Unity面经(自整)——移动开发与Shader
  • Nginx实现反向代理、负载均衡、动静分离
  • 【Linux】网络基础(一)
  • 前端小白学习Vue框架(二)
  • 飞书api增加权限
  • CSS3 平面 2D 变换+CSS3 过渡
  • 【Jenkins】Jenkins自动化工具介绍
  • 课时93:流程控制_函数进阶_综合练习
  • oracle创建整个数据库的只读账户
  • 文件名乱码危机:数据恢复全攻略
  • Unity Standalone File Browser,Unity打开文件选择器
  • 面向对象的架构三段式写一篇论文
  • npm ERR! code CERT_HAS_EXPIREDnpm ERR! errno CERT_HAS_EXPIRED
  • pytorch-多分类实战之手写数字识别
  • httpsok-快速申请谷歌SSL免费证书
  • LiveGBS流媒体平台GB/T28181功能-国标级联中如何自定义通道国标编号编辑通道编号保持唯一性
  • mysql 大表凌晨定时删除数据
  • ArcGIS和ArcGIS Pro快速加载ArcGIS历史影像World Imagery Wayback
  • 数据仓库的—数据仓库的体系架构
  • 【C/C++基础知识】const 关键字
  • Docker之数据卷和Dockerfile
  • pull拉取最新代码
  • 工控 modbusTCP 报文
  • 在Ubuntu服务器上快速安装一个redis并提供远程服务
  • 玩机进阶教程------手机定制机 定制系统 解除系统安装软件限制的一些步骤解析
  • Bilstm双向长短期神经网络多输入单输出回归分析
  • ELK+Filebeat日志分析系统