Java-IDEA環境搭建swagger


1.項目POM導入包(使用Maven管理的代碼)

  

 

2.POM文件導入包 

 1 <dependencyManagement>
 2         <dependencies>
 3             <dependency>
 4                 <groupId>io.swagger</groupId>
 5                 <artifactId>swagger-annotations</artifactId>
 6                 <version>1.5.14</version>
 7             </dependency>
 8             <dependency>
 9                 <groupId>io.springfox</groupId>
10                 <artifactId>springfox-swagger2</artifactId>
11                 <version>2.7.0</version>
12             </dependency>
13             <dependency>
14                 <groupId>io.springfox</groupId>
15                 <artifactId>springfox-swagger-ui</artifactId>
16                 <version>2.7.0</version>
17             </dependency>
18 
19         </dependencies>
20     </dependencyManagement>

3.啟動項目導入pom文件

 

 1     <dependencies>
 2         <dependency>
 3             <groupId>io.swagger</groupId>
 4             <artifactId>swagger-annotations</artifactId>
 5         </dependency>
 6         <dependency>
 7             <groupId>io.springfox</groupId>
 8             <artifactId>springfox-swagger2</artifactId>
 9         </dependency>
10         <dependency>
11             <groupId>io.springfox</groupId>
12             <artifactId>springfox-swagger-ui</artifactId>
13         </dependency>
14     </dependencies>

 

 

 

4.WebConfig 配置

 

 1  /**
 2      * 發現如果繼承了WebMvcConfigurationSupport,則在yml中配置的相關內容會失效。
 3      * 需要重新指定靜態資源
 4      * @param registry
 5      */
 6     @Override
 7     public void addResourceHandlers(ResourceHandlerRegistry registry) {
 8         registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
 9         registry.addResourceHandler("swagger-ui.html")
10                 .addResourceLocations("classpath:/META-INF/resources/");
11         registry.addResourceHandler("/webjars/**")
12                 .addResourceLocations("classpath:/META-INF/resources/webjars/");
13         super.addResourceHandlers(registry);
14     }

5.增加啟動的注入掃描 (@EnableSwagger2)

 

 6.項目啟動后運行效果,查看swagger

 

 

 

7.接口參數相關效果

8.代碼接口配置(更多配置注解請查看 https://blog.csdn.net/xiaojin21cen/article/details/78654652

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM