日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

解決springboot集成swagger碰到的坑(報404)

瀏覽:28日期:2023-03-05 08:40:26
一:項目使用springboot集成swagger進行調試

配置swagger非常簡單,主要有三步:

1、添加swagger依賴

<!-- 引入 swagger等相關依賴 --><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version></dependency>2、進行swagger的配置

package com.sailing.springbootmybatis.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import springfox.documentation.builders.ApiInfoBuilder;import springfox.documentation.builders.PathSelectors;import springfox.documentation.builders.RequestHandlerSelectors;import springfox.documentation.service.ApiInfo;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket;import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * @author baibing * @project: springboot-mybatis * @package: com.sailing.springbootmybatis.config * @Description: swagger2配置類 * @date 2018/9/25 15:35 */@Configuration@EnableSwagger2public class Swagger2Config { @Bean public Docket createRestApi(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage('com.sailing.springbootmybatis.controller')).paths(PathSelectors.any()).build(); } private ApiInfo apiInfo(){return new ApiInfoBuilder().title('SPRING-BOOT整合MYBATIS--API說明文檔').description('2018-8完成版本').contact('Sailing西安研發中心-baibing').version('1.0').license('署名-非商用-相同方式共享 4.0轉載請保留原文鏈接及作者').licenseUrl('https://creativecommons.org/licenses/by-nc-sa/4.0/').build(); }}3、在controller層添加相應的注解(@Api 和 @ApiOperation 以及 @ApiIgnore 等)

package com.sailing.springbootmybatis.controller;import com.sailing.springbootmybatis.bean.Userinfo;import com.sailing.springbootmybatis.common.log.LogOperationEnum;import com.sailing.springbootmybatis.common.log.annotation.MyLog;import com.sailing.springbootmybatis.common.response.BuildResponseUtil;import com.sailing.springbootmybatis.common.response.ResponseData;import com.sailing.springbootmybatis.common.websocket.WebSocketServer;import com.sailing.springbootmybatis.service.RedisService;import com.sailing.springbootmybatis.service.UserinfoService;import io.swagger.annotations.Api;import io.swagger.annotations.ApiOperation;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.validation.BindingResult;import org.springframework.web.bind.annotation.*;import springfox.documentation.annotations.ApiIgnore;import javax.validation.Valid;import java.io.IOException;import java.util.List; /** * @author baibing * @project: springboot-mybatis * @package: com.sailing.springbootmybatis.controller * @Description: Userinfo controller 控制層 * @date 2018/9/12 10:07 */@RestController@Api(value = 'USERINFO', description = '用戶信息測試controller')public class UserinfoController{ @Autowired private UserinfoService userinfoService; @Autowired private WebSocketServer webSocketServer; @Autowired private RedisService redisService; /** * 查找指定id對應的用戶 * @param id * @return */ @RequestMapping(value = '/user/{id}', method = RequestMethod.GET) @MyLog(type = LogOperationEnum.SELECT,value = '查詢指定id的用戶信息') @ApiOperation(value = '查詢指定id的用戶信息接口', notes = '查詢指定id的用戶信息接口') public ResponseData getUser(@PathVariable(value = 'id') Integer id){return userinfoService.findById(id); } /** * 查找所有用戶 * @return */ @RequestMapping(value = '/users', method = RequestMethod.GET) @MyLog(type = LogOperationEnum.SELECT,value = '查詢全部用戶信息') @ApiOperation(value = '查詢所有用戶信息接口', notes = '查詢所有用戶信息接口') public ResponseData getAllUsers(){return userinfoService.findAllUsers(); } /** * 查找所有用戶(帶分頁) * @param page 當前頁數 * @param rows 每頁顯示條數 * @return */ @RequestMapping(value = '/users/p', method = RequestMethod.GET) @ApiOperation(value = '查詢所有用戶信息接口(帶分頁)', notes = '查詢所有用戶信息接口(帶分頁)') public ResponseData getAllUsers(Integer page, Integer rows){return userinfoService.findAllUsers(page, rows); } /** * 新增用戶 (帶參數校驗@Valid) * 注意:BindingResult 對象必須在 @Valid 的緊挨著的后面,否則接收不到錯誤信息 * @Valid 可以校驗json 也可以校驗表單傳遞的對象屬性 * @param userinfo * @return */ @RequestMapping(value = '/user', method = RequestMethod.POST) @MyLog(type = LogOperationEnum.INSERT, value = '新增用戶信息') @ApiOperation(value = '新增用戶接口(包含參數校驗)', notes = '新增用戶接口(包含參數校驗)') public ResponseData saveUserinfo(@RequestBody @Valid Userinfo userinfo, BindingResult bindingResult){if(bindingResult.hasErrors()){ return BuildResponseUtil.buildFailResponse(bindingResult.getFieldError().getDefaultMessage());}return userinfoService.saveUser(userinfo); } /** * 刪除指定用戶 * @param id 用戶id * @return */ @RequestMapping(value = '/user/{id}', method = RequestMethod.DELETE) @ApiOperation(value = '刪除指定id的用戶信息接口', notes = '刪除指定id的用戶信息接口') public ResponseData deleteUser(@PathVariable Integer id){return userinfoService.deleteUser(id); } /** * 更新用戶 * @param userinfo * @return */ @RequestMapping(value = '/user', method = RequestMethod.PUT) @ApiOperation(value = '更新指定id用戶信息接口', notes = '更新指定id用戶信息接口') public ResponseData updateUserinfo(@RequestBody Userinfo userinfo){return userinfoService.updateUser(userinfo); } /** * 給指定用戶推送消息 * @param userName 用戶名 * @param message 消息 * @throws IOException */ @RequestMapping(value = '/socket', method = RequestMethod.GET) @ApiIgnore //使用此注解忽略方法的暴露,也可以用在controller上 @ApiOperation(value = '給指定用戶推送socket消息接口', notes = '給指定用戶推送socket消息接口') public void testSocket(@RequestParam String userName,@RequestParam String message){webSocketServer.sendInfo(userName, message); } /** * 測試redis接口保存String類型action * @param address * @return */ @RequestMapping(value = '/redis', method = RequestMethod.POST) @ApiIgnore //使用此注解忽略方法的暴露,也可以用在controller上 @ApiOperation(value = 'redis中添加String數據接口', notes = 'redis中添加String數據接口') public ResponseData setString(@RequestBody String address){System.out.println(address);return redisService.setValue(address); } /** * 測試redis接口保存實體類型action * @param userinfo * @return */ @RequestMapping(value = '/redis/userinfo', method = RequestMethod.POST) @ApiIgnore //使用此注解忽略方法的暴露,也可以用在controller上 @ApiOperation(value = 'redis中添加Userinfo實體接口', notes = 'redis中添加Userinfo實體接口') public ResponseData setEntity(@RequestBody Userinfo userinfo){return redisService.setEntityValue(userinfo); } /** * 測試redis接口讀取實體類型action * @param key * @return */ @RequestMapping(value = '/redis/userinfo/{key}', method = RequestMethod.GET) @ApiIgnore //使用此注解忽略方法的暴露,也可以用在controller上 @ApiOperation(value = 'redis中讀取指定key對應的數據接口', notes = 'redis中讀取指定key對應的數據接口') public ResponseData getEntity(@PathVariable String key){return redisService.getEntityValue(key); } /** * * @param list * @return */ @RequestMapping(value = '/redis/userList', method = RequestMethod.POST) @ApiIgnore //使用此注解忽略方法的暴露,也可以用在controller上 @ApiOperation(value = 'redis中添加包含Userinfo實體的集合接口', notes = 'redis中添加包含Userinfo實體的集合接口') public ResponseData setCollection(@RequestBody List<Userinfo> list){return redisService.setCollectionValue(list); } /** * 測試redis接口讀取實體類型action * @param key * @return */ @RequestMapping(value = '/redis/userList/{key}', method = RequestMethod.GET) @ApiOperation(value = 'redis中讀取指定key對應的集合數據接口', notes = 'redis中讀取指定key對應的集合數據接口') public ResponseData getCollection(@PathVariable String key){return redisService.getCollectionValue(key); }}二:到這里配置就結束了

訪問 http://127.0.0.1:端口/項目路徑/swagger-ui.html 就ok了, 頁面如下:

解決springboot集成swagger碰到的坑(報404)

swagger-ui界面展示

三:項目運行了一段時間后訪問上面連接突然報 404 錯誤

百思不得其解,但是可以肯定的是加了什么配置導致,最后在application.yml 中發現了一個配置:

spring.mvv.resources.add-mapping:false

將其注釋掉熟悉的界面又回來了,查閱資料發現這個配置是不自動給靜態資源添加路徑,導致swagger-ui.html找不到資源,知道原因后摸索看能不能在保留以上配置的前提下自己手動給swagger-ui.html添加靜態資源路徑呢?

package com.sailing.springbootmybatis.config;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * 在SpringBoot2.0及Spring 5.0 WebMvcConfigurerAdapter已被廢棄,目前找到解決方案就有 * 1 直接實現WebMvcConfigurer (官方推薦) * 2 直接繼承WebMvcConfigurationSupport * @ https://blog.csdn.net/lenkvin/article/details/79482205 */@Configurationpublic class WebMvcConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler('swagger-ui.html').addResourceLocations('classpath:/META-INF/resources/');registry.addResourceHandler('/webjars/**').addResourceLocations('classpath:/META-INF/resources/webjars/'); }}

發現通過以上代碼手動給swagger-ui.html指定路徑也可以解決404的問題。

Springboot集成Swagger遇到無限死循環解決方法

1.萬能辦法,重啟,我自己用好使

2.同事說的方法,因重啟無效,斷網一會

3.修改端口號,目前一直用的

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
91亚洲国产成人久久精品| 久久精品国产亚洲aⅴ| 欧美日韩国产观看视频| 麻豆精品视频在线| 另类小说一区二区三区| 国产精品流白浆在线观看| 国产午夜久久av| 国产视频一区二区在线播放| 国产日韩欧美三区| 国产乱人伦精品一区| 日韩av网站免费在线| 亚洲精品亚洲人成在线观看| 玖玖精品视频| 亚洲制服一区| 欧美精品影院| 精品在线网站观看| 精品日韩在线| 久久久久国产精品一区三寸| 99久久亚洲精品| 黄色精品网站| 日韩有吗在线观看| 麻豆精品国产91久久久久久| 91麻豆国产自产在线观看亚洲| 香蕉视频亚洲一级| 午夜欧美理论片| 性色一区二区| 91精品视频一区二区| 国产精久久久| 美女一区网站| 在线亚洲自拍| 国产日韩欧美高清免费| 国产白浆在线免费观看| 免费不卡中文字幕在线| 一区二区电影在线观看| 国产精品亲子伦av一区二区三区| 国产精品yjizz视频网| 成人av二区| 91伊人久久| 日韩免费小视频| 免费成人av在线播放| 欧美日韩亚洲三区| 成人福利av| 亚洲精品动态| 福利视频一区| 日韩中文字幕麻豆| 麻豆国产精品777777在线| 高清久久精品| 亚洲精品1区2区| 国产精品a级| 久久久久久久久久久妇女| 日韩中文字幕麻豆| 精品一级视频| 麻豆久久精品| 国产成人精选| 日本大胆欧美人术艺术动态| 国产精品扒开腿做爽爽爽软件| 福利在线免费视频| 丝袜国产日韩另类美女| 麻豆91在线播放| 国产日韩综合| 欧美激情麻豆| 亚洲欧美日韩国产| 国产一区丝袜| 在线观看亚洲精品福利片| 狠狠久久伊人| 亚洲精品综合| 免费污视频在线一区| 婷婷成人av| 99国产精品一区二区| 欧美在线看片| 欧美日韩国产一区二区三区不卡| 91欧美日韩在线| 欧美成人精品| 美女在线视频一区| 香蕉成人久久| 久久久久午夜电影| 欧美国产另类| 中文字幕av亚洲精品一部二部| 亚洲va中文在线播放免费| 国产调教一区二区三区| 99riav1国产精品视频| 久久一区欧美| 日韩高清一区在线| 婷婷亚洲综合| av在线最新| 国产精品一站二站| 亚洲欧洲日本mm| 92国产精品| 国产精选久久| 中文字幕乱码亚洲无线精品一区| 日韩一区三区| 免费一区二区三区在线视频| 视频一区二区不卡| 91精品国产调教在线观看| 欧美xxxx性| 色综合视频一区二区三区日韩 | 国产精品外国| 国产理论在线| 日韩成人午夜精品| 蜜桃视频一区二区三区| 欧美日韩在线精品一区二区三区激情综合| 久久中文字幕av| 成人精品国产亚洲| 麻豆国产一区| 国产欧美日韩精品一区二区免费| 亚洲欧美成人综合| 亚洲国产成人精品女人| 久久影院午夜精品| 国产一区二区三区免费在线| 日韩中文字幕一区二区高清99| 99成人在线| 亚洲女同中文字幕| 久久在线视频免费观看| 日韩欧美精品一区| 成人在线丰满少妇av| 麻豆精品蜜桃视频网站| 国产伦一区二区三区| 日本不卡视频在线观看| 日韩影院精彩在线| 蜜臀久久99精品久久久画质超高清 | 日韩一区二区在线免费| 国产精品videosex极品| 欧美日韩亚洲三区| 国产探花在线精品| 国产精品最新| 麻豆国产一区| 国产66精品| 97在线精品| 日韩精品诱惑一区?区三区| 91日韩免费| 日本少妇一区| 精品一区三区| 模特精品在线| 中文字幕亚洲精品乱码| 日韩av一区二区三区四区| 日欧美一区二区| 欧美一区久久| 国产精品99久久久久久董美香| 精品一区电影| 一区二区精品伦理...| www.com.cn成人| 欧美日韩精品一区二区视频| 亚洲午夜一级| 日韩精品一二三区| 国产欧美啪啪| 国产传媒在线观看| 一区二区小说| 亚洲一区二区三区高清不卡| 蜜桃视频免费观看一区| 日韩av一区二区三区| 久久狠狠久久| 狠狠久久伊人| 免费精品国产的网站免费观看| 亚洲免费网址| 欧美天堂一区| 色综合五月天| 日韩不卡一区二区三区| 日韩免费精品| 日韩一区二区久久| 亚洲伊人精品酒店| 不卡视频在线| 国产69精品久久| 福利视频一区| 国产欧美日韩精品一区二区免费| 蜜桃久久久久| 亚洲2区在线| 91tv亚洲精品香蕉国产一区| 亚洲成人精品| 亚洲精品乱码久久久久久蜜桃麻豆| 久久国产麻豆精品| 成人日韩在线观看| 视频一区视频二区中文| 国产精品a级| 久久久久久久久99精品大| | 日韩午夜免费| 国产伦精品一区二区三区千人斩| 日韩福利一区| 欧美日韩视频| 欧美天堂一区| 国产中文一区| 日韩高清二区| 日韩美女一区二区三区在线观看| 三级在线观看一区二区| 乱一区二区av| 欧美午夜不卡| 国产精品丝袜在线播放| 少妇精品导航| 日本成人在线不卡视频| 神马午夜在线视频| 日韩成人av影视| 国产精品7m凸凹视频分类| 国产伦理久久久久久妇女| 九色porny丨国产首页在线| 日韩在线观看中文字幕| 五月天av在线| 国产日韩一区二区三免费高清 | 麻豆mv在线观看| 亚洲久久一区| 神马午夜久久|