引言
之前发过一篇 Spring Boot 整合Swagger2 的文章
继续Swagger3
依赖
1 2 3 4 5 6
| <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
|
配置
1 2 3 4 5 6 7
| # swagger3 配置 swagger.service.enable=是否开启Swagger3 swagger.service.title=标题 swagger.service.version=版本 swagger.service.description=说明 swagger.service.group-name=分组 swagger.service.base-package=controller路径
|
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.oas.annotations.EnableOpenApi; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket;
@Data @EnableOpenApi @Configuration @ConfigurationProperties(prefix = "swagger.service") public class Swagger3Config {
private Boolean enable;
private String title;
private String version;
private String description;
private String groupName;
private String basePackage;
@Bean public Docket docket() { return new Docket(DocumentationType.OAS_30) .apiInfo(apiInfo()) .enable(enable) .groupName(groupName) .select() .apis(RequestHandlerSelectors.basePackage(basePackage)) .paths(PathSelectors.any()) .build(); }
private ApiInfo apiInfo() { return new ApiInfoBuilder() .title(title) .description(description) .version(version) .build(); }
}
|
访问
Swagger3 的访问路径也有些变化
http://localhost:8080/swagger-ui/index.html
后续
Swagger3 也是支持可以传入Token的,可以搜一搜,我这边就不展示了
之后我会推出一篇文章讲解软件Apifox的文章,自我感觉比postman好用。可以在上边设置一下全局token,简单清晰。