SpringBoot統合闊歩
1.闊歩とは何ですか
闊歩は、RESTfulなWebサービスの作成、記述、および可視化の呼び出しのための標準化され、完全なフレームワークです。それは単にプロジェクト稼働している、あなたのインターフェースの可視化を展開しました。
2. SpringBootで闊歩を使用する方法
1.設定のpom.xml
ここでは、インターフェイスの使用状況のレイアウトについて人々に沿って、オープンソースのディスプレイインタフェースパッケージをコンテンツ闊歩をインポートして、追加のインポート
<!-- 自动生成API文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- Swagger UI插件 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- 开源的api接口显示界面,左右布局 -->
<dependency>
<groupId>com.github.caspar-chen</groupId>
<artifactId>swagger-ui-layer</artifactId>
<version>1.1.3</version>
</dependency>
2.書き込み闊歩の設定クラス
package com.xxx.xxx.config;
import org.springframework.beans.factory.annotation.Value;
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;
/**
* 配置Swagger2
*
* @author axiang
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
/**
* 关闭 swagger,从配置文件中读取内容,这里这么做是将生产环境和开发环境的配置区分开来,毕竟你不会想在实际生产环境中开放接口文档给其他人的
* @Value 注解的作用可查看百度,这里不多做解释
*/
@Value("${xxx.swagger.enable}")
private boolean enableSwagger;
private String title = "xxx项目接口文档";
private String description = "xxx项目接口文档,Spring boot版";
private String version = "1.0.0";
private String termsOfServiceUrl = "";
private String license = "";
private String licenseUrl = "";
@Bean
public Docket api() {
// 允许开启swagger
if (enableSwagger) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 扫描Controller所在的包
.apis(RequestHandlerSelectors.basePackage("xxx.xxx.controller"))
.paths(PathSelectors.any())
.build();
} else {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.paths(PathSelectors.none())
.build();
}
}
private ApiInfo apiInfo() {
// 具体内容是什么功能请百度相关文档
return new ApiInfoBuilder()
.title(title)
.description(description)
.version(version)
.termsOfServiceUrl(termsOfServiceUrl)
.license(license)
.licenseUrl(licenseUrl)
.build();
}
}
3.
私たちは、サードパーティのインタフェースパッケージを使用するので、それは二つの経路を介してアクセスすることができる
インターフェイスパックは、ああ、まだ動作していない威張っと呼ばれるサードパーティのインターフェース、とても近く、サードパーティのインタフェースパッケージ後に闊歩であることに注意してください
# 原装正品请访问
http://[IP地址]:[端口号]/[项目路径]/swagger-ui.html
# 左右布局请访问
http://[IP地址]:[端口号]/[项目路径]/docs.html