Swagger3测试工具使用流程
一:简介
Swagger是一个开源的软件框架,可以帮助开发人员设计,构建和使用Web服务,将代码和文档结合在一起,使得开发人员将大部分精力集中到业务中,而不是文档的撰写。
二:Swagger3.0的改动
1.删除了对Springfox-swagger2的依赖; 2.删除所有@EnableSwagger2…注解; 3.添加了springfox-boot-starter的依赖项; 4.移除了guava等第三方依赖; 5.文档的访问地址改为:http://ip:port/project/swagger-ui/index.html
三:Springboot集成Swagger3流程
●SpringBoot集成Swagger3与SpringBoot集成其他的框架套路基本一致,通常为:引入依赖,编写application.properties,创建配置类和使用。
1.引入依赖
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
2.配置Swagger3
/** * swagger配置类 */ @Configuration public class SwaggerConfig { @Bean public Docket createRestApi() { //Docker---对象,测试就放在此对象中进行 return new Docket(DocumentationType.OAS_30) //配置版本号 .apiInfo(apiInfo()) //页面显示 .select() .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("宠物智慧平台的Swagger3接口文档") //项目描述 .description("描述项目的接口生成文档") .contact(new Contact("dyit", "http://www.dyit.com", "dyit@dyit.com")) .version("1.0") //版本号 .build(); } }
- 使用swagger注解 1)在启动类上:@EnableOpenApi 2)在Controller类中: @Api(tags=“信息描述”) @ApiOperation(“板块信息描述”) 4.查看结果
启动SpringBoot项目,然后访问地址
上一篇:
Python 安装包管理工具 pip
下一篇:
IDEA添加自动注释(类注释及方法注释)