日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringMvc之集成Swagger

發(fā)布時(shí)間:2025/5/22 javascript 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringMvc之集成Swagger 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1 搭建springmvc環(huán)境(此處省略)

?

2 導(dǎo)入額外需要的相關(guān)jar

swagger-springmvc-1.0.0.jar

swagger-models-1.0.0.jar

swagger-core-1.5.0.jar

swagger-annotations-1.3.11.jar

jackson-core-2.4.4.jar

jackson-annotations-2.4.0.jar

guava-15.0.jar

classmate-1.1.0.jar

?

3 新建MySwaggerConfig配置文件

package com.zns;import com.mangofactory.swagger.configuration.SpringSwaggerConfig; import com.mangofactory.swagger.models.dto.ApiInfo; import com.mangofactory.swagger.plugin.EnableSwagger; import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc;@Configuration @EnableSwagger @EnableWebMvc public class MySwaggerConfig {private SpringSwaggerConfig springSwaggerConfig;/*** Required to autowire SpringSwaggerConfig*/@Autowiredpublic void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig){this.springSwaggerConfig = springSwaggerConfig;}/*** Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc* framework - allowing for multiple swagger groups i.e. same code base* multiple swagger resource listings.*/@Beanpublic SwaggerSpringMvcPlugin customImplementation(){return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(".*?");}private ApiInfo apiInfo(){ApiInfo apiInfo = new ApiInfo("My Apps API Title","My Apps API Description","My Apps API terms of service","My Apps API Contact Email","My Apps API Licence Type","My Apps API License URL");return apiInfo;} }

?

?

4 在springmvc配置文件加入

<bean class="com.zns.MySwaggerConfig" />

?

?

5 從https://github.com/swagger-api/swagger-ui 下載swagger-ui

?

6 在WebContent中新建一個(gè)swagger文件夾(可以任意取名),然后將下載的swagger-ui解壓后將dist下的所有文件放到swagger文件夾下

?

7 修改swagger/index.html文件,默認(rèn)是從連接http://petstore.swagger.io/v2/swagger.json獲取 API 的 JSON,這里需要將url值修改為http://{ip}:{port}/{projectName}/api-docs的形式

? 比如http://localhost:8080/項(xiàng)目名/api-docs

?

8 啟動(dòng)項(xiàng)目

訪問http://localhost:8080/項(xiàng)目名/swagger/index.html,即可看到接口列表

?

經(jīng)測(cè)試 springmvc4.0.0 + swagger-ui-2.1.2 可用!

?

轉(zhuǎn)載于:https://www.cnblogs.com/zengnansheng/p/10385833.html

總結(jié)

以上是生活随笔為你收集整理的SpringMvc之集成Swagger的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。