我是靠谱客的博主 健康唇膏,这篇文章主要介绍SpringBoot2.6.2及Swagger3使用一、swagger的pom.xml引入二、增加配置类三、增加配置application.yml四、测试,现在分享给大家,希望可以做个参考。
SpringBoot2.6.2及Swagger3使用
- 一、swagger的pom.xml引入
- 二、增加配置类
- 三、增加配置application.yml
- 四、测试
一、swagger的pom.xml引入
复制代码
1
2
3
4
5
6
7<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
二、增加配置类
复制代码
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
56package cn.gzsendi.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; import org.springframework.context.annotation.Bean; 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.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; /** * @Description: Swagger3配置文件 * http://localhost:18181/aiVideoSystem/swagger-ui/index.html */ @SpringBootConfiguration @EnableOpenApi public class Swagger3Config { private static final String PACKAGE = "cn.gzsendi"; /** * application中还配置了mvc,因为springboot2.6.2与swagger3不兼容 */ /** * ture 启用Swagger3.0, false 禁用(生产环境要禁用) */ //是否开启swagger功能 @Value("${swagger.enabled:true}") private boolean swaggerEnabled; @Bean public Docket createRestApi(){ return new Docket(DocumentationType.OAS_30) .apiInfo(apiInfo()) // 是否开启 .enable(swaggerEnabled) .select() // 扫描的路径使用@Api的controller .apis(RequestHandlerSelectors.basePackage(PACKAGE)) // 配置了@ApiOperation的注解的才暴露给swagger //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 指定路径处理PathSelectors.any()代表所有的路径 .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo(){ return new ApiInfoBuilder() .title("Swagger3接口文档") .description("spring boot 系统管理接口文档") //作者信息 .contact(new Contact("admin","https://test123456.com/", "123456@qq.com")) .version("1.0") .build(); } }
三、增加配置application.yml
复制代码
1
2
3
4
5
6
7
8
9spring: #swagger3 需配置,不然展示不了列表,这个mvc的配置是springboot2.6.2不支持swagger3的折衷配置,可考虑升级Springboot版本或降级版本 mvc: pathmatch: matching-strategy: ant_path_matcher #是否开启swagger,不设置默认值为true,生产环境中建议设置成false swagger: enabled: true
四、测试
复制代码
1
2http://Ip:Port/swagger-ui/index.html
本文内容参考https://blog.csdn.net/yao22yao/article/details/125207679
最后
以上就是健康唇膏最近收集整理的关于SpringBoot2.6.2及Swagger3使用一、swagger的pom.xml引入二、增加配置类三、增加配置application.yml四、测试的全部内容,更多相关SpringBoot2.6.2及Swagger3使用一、swagger内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复