Springfox swagger30项目配置和实战

由于项目重构,所以需要从springboot 1.5.7版本切换到2.5.6
但切换后出现了swagger 依赖冲突的问题,所以swagger也要换到3.0的版本

首先可以直接引入springfox-boot-starter,这样就简洁点引入依赖了

1
2
3
4
5
xml复制代码<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>

然后修改swagger 配置类,我这里没有用到很多的属性,所以就直接点
其实改动点就是

1
复制代码DocumentationType SWAGGER_2换成了DocumentationType.OAS_30

配置类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
less复制代码@Configuration
@ConditionalOnProperty(prefix="swagger",value={"enable"},havingValue="true")
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.meicloud.meidevops.controller"))
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("devops api")
.description("devops")
.termsOfServiceUrl("https://www.meicloud.com")
.version("1.0")
.build();
}
}

然后启动访问http://localhost:8082/swagger-ui/index.html#/

image.png

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%