SpringMVC+Swagger2快速整合,以及遇到的各種問題解決方案

通過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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章