Swagger3.0 整合spring boot2.7x避免swagger2.0與boot2.7沖突問題
更新時間:2023年10月13日 09:31:31 作者:北涼軍
這篇文章主要介紹了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匹配規(guī)則即可

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 內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
基于Java實現楊輝三角 LeetCode Pascal''s Triangle
這篇文章主要介紹了基于Java實現楊輝三角 LeetCode Pascal's Triangle的相關資料,需要的朋友可以參考下2016-01-01
解決mybatis使用char類型字段查詢oracle數據庫時結果返回null問題
這篇文章主要介紹了mybatis使用char類型字段查詢oracle數據庫時結果返回null問題的解決方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-06-06

