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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

(十二)java版电子商务spring cloud分布式微服务- Spring 4.2.2以上版本和swagger集成方案和踩过的坑...

發布時間:2025/3/18 javascript 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (十二)java版电子商务spring cloud分布式微服务- Spring 4.2.2以上版本和swagger集成方案和踩过的坑... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

電子商務平臺源碼請加企鵝求求:一零三八七七四六二六。因為公司使用的spring版本太高,在集成swagger的時候會存在一些問題,而網上的很多實例大多都是版本比較低的,為了是朋友們少才坑,我這邊將集成的過程記錄一下:

引入spring、swagger的相關jar包(springfox-swagger2、springfox-swagger-ui),在pom.xml中配置:

<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency> 復制代碼

提醒: 特別注意,springfox-swagger2在集成的時候,已經引入了spring的相關jar,特別是spring-context、spring-context-support的版本和項目中使用的版本完全不一致,項目在啟動的時候出現很多包沖突的問題,這邊在引入pom.xml文件的時候過濾掉了spring的相關jar包,如綠色標志。

編寫Swagger的配置類:

package com.ml.honghu.swagger.web; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @EnableWebMvc @EnableSwagger2 @Configuration @ComponentScan(basePackages ={"com.ml.honghu.**.rest"}) public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.ml.honghu")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("接口列表 v1.0") .description("接口信息") .termsOfServiceUrl("http://honghu.com") .contact(new Contact("", "", "HongHu")) .version("1.1.0") .build(); } } 復制代碼

提醒:注意紅色標注的地方

在spring-mvc.xml文件中進行過濾器的配置,過濾掉swagger的相關訪問配置:

<mvc:exclude-mapping path="/swagger*/**"/> <mvc:exclude-mapping path="/v2/**"/> <mvc:exclude-mapping path="/webjars/**"/> 復制代碼

服務配置項

<span style="color: #ff0000;">@Api("區域服務")</span> @RestController @RequestMapping(value = "/rest/area") public class AreaService { @Autowired private AreaService areaService; <span style="color: #ff0000;">@ApiOperation(value = "區域列表", httpMethod = "GET", notes = "區域列表")</span> @IsLogin @ResponseBody @RequestMapping(value = "treeData", method = RequestMethod.GET) public List<Map<String, Object>> treeData( <span style="color: #ff0000;">@ApiParam(required = true, value = "區域ID")</span> @RequestParam(required=false) String extId, HttpServletResponse response) { List<Map<String, Object>> mapList = Lists.newArrayList(); List<Area> list = areaService.findAll(); for (int i=0; i<list.size(); i++){ Area e = list.get(i); if (StringUtils.isBlank(extId) || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){ Map<String, Object> map = Maps.newHashMap(); map.put("id", e.getId()); map.put("pId", e.getParentId()); map.put("name", e.getName()); mapList.add(map); } } return mapList; } } 復制代碼

啟動項目,查看結果:

到此結束!!

轉載于:https://juejin.im/post/5ceb534d6fb9a07ef819da5a

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的(十二)java版电子商务spring cloud分布式微服务- Spring 4.2.2以上版本和swagger集成方案和踩过的坑...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品一区二区三区四区五区 | 久久久www| 中国少妇乱子伦视频播放 | www.五月天com | 亚洲色图网友自拍 | 天天干天天操天天操 | 久久久久亚洲av无码专区 | 少妇精品无码一区二区免费视频 | 就要爱爱tv | 黑人操中国女人视频 | 国内精品在线观看视频 | 天天操天天射天天舔 | 精品久久久久久无码国产 | 秋霞亚洲 | tube国产麻豆| 青青草国产在线视频 | 91在线欧美| 热99视频| 国产一区欧美一区 | 日韩视频在线播放 | 一区二区麻豆 | 亚洲av毛片一区二二区三三区 | 中文字幕乱视频 | 午夜精品福利一区二区 | 欢乐谷在线观看免费播放高清 | www.av在线视频 | 欧洲xxxxx | 免费特级黄毛片 | 人人妻人人澡人人爽国产一区 | 欧美日韩国产综合网 | 国产一区二区视频在线观看 | 淫语对白 | 狠狠操女人 | 欧美亚洲在线视频 | 乌克兰做爰xxxⅹ性视频 | 免费的毛片视频 | 国产99久一区二区三区a片 | 国产91精品露脸国语对白 | 国产 福利 在线 | 午夜污污| 亚洲免费av一区二区 | 91天天操| 亚洲欧美日韩一区二区三区四区 | 可以在线观看的av | 亚洲一区av在线 | 亚洲午夜久久久久久久久 | 色在线影院 | 亚洲xx站| 黄色a在线观看 | 在线中文视频 | 男人天堂导航 | 国产素人自拍 | 久久久久久久久久亚洲 | 国产无毛av| 国产毛片毛片毛片毛片毛片毛片 | 久久九色 | 午夜在线一区二区 | 久久精品日韩 | 久射网| 两性视频久久 | 国产人澡人澡澡澡人碰视频 | 亚洲资源在线 | 精品人妻无码中文字幕18禁 | 午夜h视频 | 国产热热 | 欧美亚洲综合视频 | 国产青青| 夜夜欢天天干 | 天天撸一撸 | 久久久国产精华液 | 美日韩成人 | 久久一区| 九七精品 | 综合另类| 亚洲精品乱码久久久久久国产主播 | 国产精品黄色大片 | 在线国产精品一区 | 蜜桃av一区 | 四虎国产精品成人免费入口 | 亚洲无在线观看 | 狠狠爱综合| 黄色av免费在线播放 | 成年人视频网址 | 日韩激情视频网站 | 国产ts丝袜人妖系列视频 | 欧美高清视频一区二区 | 射在线| 涩涩涩涩涩涩涩涩涩 | www裸玉足久久久 | 中文字幕精品一区二 | 久久一道本 | 天天综合色网 | 97超碰在线免费 | 国产电影一区二区三区爱妃记 | 日本少妇喷水视频 | 天堂免费在线视频 | 精品人人妻人人澡人人爽牛牛 | 国产乱国产乱老熟300部视频 | 青草一区 |