一、Swagger2
SpringBoot2.xxx maven 项目中引入Swagger2两种方式:
1、官方依赖包
<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>
2、第三方依赖包
<dependency> <groupId>com.spring4all</groupId> <artifactId>swagger-spring-boot-starter</artifactId> <version>1.7.0.RELEASE</version> </dependency>
javaConfig配置代码案列:
@Configuration @EnableSwagger2 public class SwaggerConfig { /** * 用于配置swagger2,包含文档基本信息 */ @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) // .host("域名/ip.com") //配置域名、对应ip等具体服务器 .pathMapping("/") //本地测试配置路径 // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) .apiInfo(apiInfo()) // 设置哪些接口暴露给Swagger展示 .select() // 灵活使用 扫描所有有注解的api // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 扫描指定controller层包下有注解的对外暴露接口 .apis(RequestHandlerSelectors.basePackage("com.xx.controller")) // 扫描所有 .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } /** * 添加摘要信息 */ private ApiInfo apiInfo() { // 用ApiInfoBuilder进行定制 return new ApiInfoBuilder() .title("springboot利用swagger构建api文档") .description("简单优雅的restfun风格") .contact(new Contact("dxw", null, null))// 作者信息 .termsOfServiceUrl("http:/xxx/xxx") .version("版本号:1.0" )// 版本 .build(); } }
详细说明参考:https://blog.csdn.net/p_programmer/article/details/89426257
二、Postman