這期內(nèi)容當中小編將會給大家?guī)碛嘘P(guān)SpringBoot中怎么整合Swagger2,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
富平網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、APP開發(fā)、響應式網(wǎng)站開發(fā)等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)建站2013年開創(chuàng)至今到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設就選創(chuàng)新互聯(lián)建站。
第一步添加依賴
<!-- SwaggerUI 接口文檔 http://{ip}:{prot}/swagger-ui.html --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>{version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>{version}</version> </dependency>
第二步添加注解
@EnableSwagger2 //啟動SwaggerUI,在啟動類或Swagger配置類上添加該注解
第三步寫配置
@Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { /* //可以添加多個header或參數(shù) ParameterBuilder aParameterBuilder = new ParameterBuilder(); aParameterBuilder //參數(shù)類型支持header, cookie, body, query etc .parameterType("header") //參數(shù)名 .name("user-token") //默認值 .defaultValue("t122222") .description("用戶登錄憑證") //指定參數(shù)值的類型 .modelRef(new ModelRef("string")) //非必需,這里是全局配置 .required(false).build(); List<Parameter> aParameters = new ArrayList<>(); aParameters.add(aParameterBuilder.build()); */ return new Docket(DocumentationType.SWAGGER_2) // return new Docket(DocumentationType.SPRING_WEB) .apiInfo(apiInfo()) .pathMapping("/") .select()// 選擇那些路徑和api會生成document .apis(RequestHandlerSelectors.any())// 對所有api進行監(jiān)控 // 不顯示錯誤的接口地址 .paths(Predicates.not(PathSelectors.regex("/error.*")))// 錯誤error路徑不監(jiān)控 .paths(Predicates.not(PathSelectors.regex("/actuator.*")))// 錯誤error路徑不監(jiān)控 .paths(PathSelectors.regex("/.*"))// 對根下所有路徑進行監(jiān)控 .paths(PathSelectors.any()) // 對所有路徑進行監(jiān)控 // 自行修改為自己的包路徑 // .apis(RequestHandlerSelectors.basePackage("com.happyloves.zc.service.account.api")) .build() // .globalOperationParameters(aParameters) .enable(true); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("API接口") .description("API接口文檔") //服務條款網(wǎng)址 // .termsOfServiceUrl("https://www.google.com") .version("1.0") // .contact(new Contact("啦啦啦", "url", "email")) .build(); } }
添加依賴
<!-- swagger-bootstrap-ui是 Swagger 的增強UI 實現(xiàn),使文檔更友好一點兒 http://{ip}:{prot}/doc.html --> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.6</version> </dependency>
上述就是小編為大家分享的SpringBoot中怎么整合Swagger2了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁題目:SpringBoot中怎么整合Swagger2
文章路徑:http://muchs.cn/article10/geccgo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供服務器托管、小程序開發(fā)、App開發(fā)、外貿(mào)網(wǎng)站建設、全網(wǎng)營銷推廣、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)