springboot 2.1.6.RELEASE整合Swagger2

まず、依存性の導入

1     < modelVersion > 4.0.0 </ modelVersion > 
2      < のgroupId > com.badcat </ groupIdを> 
3      < たartifactId >デモ</ たartifactId > 
4      < バージョン> 0.0.1-SNAPSHOT </ バージョン> 
5      < パッケージ>ジャー< / パッケージング> 
6      
7      < プロパティ> 
8          < 達人-ジャーplugin.version >3.1.1</ 達人-ジャーplugin.version > 
9      </ プロパティ> 
10      
11      < > 
12          < のgroupId > org.springframework.boot </ groupIdを> 
13          < たartifactId >ばねブートスタータ親</ たartifactId > 
14          < バージョン> 2.1.6.RELEASE </ バージョン> 
15          < relativePath /> 
16      </ > 
17      
18      <依存関係> 
19          < 依存性> 
20              < のgroupId > org.springframework.boot </ groupIdを> 
21              < たartifactId >ばねブートスタータウェブ</ たartifactId > 
22          </ 依存> 
23          
24          <! - swagger2配置- > 
25          < 依存> 
26              < groupIdを> io.springfox </ groupIdを> 
27              < たartifactId >springfox-swagger2 </たartifactId > 
28              < バージョン> 2.4.0 </ バージョン> 
29          </ 依存> 
30          < 依存性> 
31              < のgroupId > io.springfox </ groupIdを> 
32              < たartifactId > springfox-闊歩-UI </ たartifactId > 
33              < バージョン> 2.4.0 </ バージョン> 
34          </ 依存> 
35          <依存関係>
36              < のgroupId > com.github.xiaoymin </ groupIdを> 
37              < たartifactId >闊歩ブートストラップ-UI </ たartifactId > 
38              < バージョン> 1.6 </ バージョン> 
39          </ 依存> 
40      </ 依存関係>

第二に、コンフィギュレーション・クラスを作成します

 

1つの パッケージcom.badcat.config。
2  
3  インポートorg.springframework.context.annotation.Bean。
4  インポートorg.springframework.context.annotation.Configuration。
5  インポートspringfox.documentation.builders.ApiInfoBuilder。
6  インポートspringfox.documentation.builders.PathSelectors。
7  インポートspringfox.documentation.builders.RequestHandlerSelectors。
8  インポートspringfox.documentation.service.ApiInfo。
9  インポートspringfox.documentation.service.Contact。
10  インポートspringfox.documentation.spi.DocumentationType。
11  インポートspringfox.documentation.spring.web.plugins.Docket。
12  インポートspringfox.documentation.swagger2.annotations.EnableSwagger2。
13  
14  @Configuration
 15  EnableSwagger2 @
 16  パブリック クラスSwagger2 {
 17  
18  //     のhttp:// localhostを:8080 /闊歩-ui.html     
 19  //     のhttp:// localhostを:8080 / doc.html     
 20  
21      // 配置swagger2核心配置ドケット
22      @Bean
 23      公衆整理createRestApi(){
 24          リターン 新しいですドケット(DocumentationType.SWAGGER_2)          // 指定されたAPI型swagger2 
25                      .apiInfo(apiInfo())                         // APIドキュメントの要約情報を定義するために使用される
26                      .Select()を
 27                      .apis(RequestHandlerSelectors
 28                              .basePackage(「com.badcat.controller 「))    // 指定されたパケットコントローラ
29                      .paths(PathSelectors.any())                 // すべてのコントローラ
30                      .build();
 31である     }
 32  
33れる     プライベートApiInfo apiInfo(){
 34が         リターン 新しい新しいApiInfoBuilder()
 35                  .TITLE( "楽屋インタフェースAPI")                        // 文書のタイトルページ
36                  が.contact(新しい新しいビジネスカード( "badcat" 37                          "https://www.xxxx.com" 38[email protected] "))                     // 連絡先情報
39                  .DESCRIPTION(" ")背景APIドキュメント                  // 詳細
40                  .version(" 1.0.1 ")                       // 発行番号
41                  .termsOfServiceUrl(" HTTPS://www.xxxx。 COM」       ) //ウェブサイトのアドレス
42れる                 )(.build;
 43である     }
 44は、 
45 }

 

第三に、プロジェクト開始

URLを入力するには、デバッグに直接、すべてのインターフェイスの情報を表示することができます。以下は、2つのスタイルであります

    http:// localhost:8080 /威張っ-ui.htmlは、http:// localhostを:8080 / doc.html

 

おすすめ

転載: www.cnblogs.com/hmxs/p/11856015.html