Swagger3.0 整合spring boot2.7x避免swagger2.0与boot2.7冲突问题
作者:北凉军
这篇文章主要介绍了Swagger3.0 整合spring boot2.7x避免swagger2.0与boot2.7冲突问题,通过注释掉2.0引入的俩包,直接引入3.0,文中结合实例代码给大家介绍的非常详细,需要的朋友参考下吧
注释掉2.0引入的俩包
直接引入3.0
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
swagger配置文件粘贴即用哦
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.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//TODO 改为你项目使用的controller包目录
.apis(RequestHandlerSelectors.basePackage("com.example.controller"))
.paths(PathSelectors.any())
.build();
}
//构建api的详细信息方法
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("xx接口文档")
//版本号
.version("1.0")
//描述
.description("swagger3.0的为基础的文档哟")
.build();
}
}最后配置文件改变mvc匹配规则即可

spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher最后
swagger2.0访问地址是:
http://localhost:8080/swagger-ui.html
swagger3.0地址是:
http://localhost:8080/swagger-ui/index.html
到此这篇关于Swagger3.0 与spring boot2.7x 整合避免swagger2.0与boot2.7冲突的文章就介绍到这了,更多相关Swagger3.0 整合spring boot2.7x 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
