通過Swagger來管理服務平臺對外提供的接口,方便開發測試,對於後臺開發中節約與客戶端開發者的交流成本,避免通過修改複雜的文檔完成接口對接,使得項目開發更具有簡潔性、高效性。
項目快速整合Swagger
實現方案:點擊查看
https://github.com/YouAreOnlyOne/FastFrameJar/tree/master/ApiConfig
最終效果
相關問題
1、配置運行正常,接口不顯示
No operations defined in spec!
SpringMVC+Swagger2 發現能出現swagger-ui.html頁面,但是無法顯示接口方法。
swagger-ui不顯示接口列表。
解決方法:
1)不要把配置文件放在controller目錄下,
2)在springmvc配置文件中添加過濾和掃描
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />
<bean id="testSwagger" class="com.construct.test.TestSwaggerApi"></bean>
2、嘗試訪問http://localhost:8080/v2/api-docs,得到的數據爲{}
查資料得知fastjson版本問題,替換即可:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
</dependency>
替換爲:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>