From 969b9c3458cead11e4feb77b52f4e0236b8bdf2c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 16 Nov 2022 21:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20swagger=20404=20=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handler/GlobalExceptionHandler.java | 6 ----- .../server/controller/DefaultController.java | 24 +++++++++++++++++++ .../src/main/resources/application.yaml | 4 ++-- 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 yudao-server/src/main/java/cn/iocoder/yudao/server/controller/DefaultController.java diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java index 05e4f0b11..28fd9b9d6 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java @@ -168,12 +168,6 @@ public class GlobalExceptionHandler { */ @ExceptionHandler(NoHandlerFoundException.class) public CommonResult noHandlerFoundExceptionHandler(HttpServletRequest req, NoHandlerFoundException ex) { - // 情况一:部分功能未开启 - if (req.getRequestURI().contains("/bpm/")) { - return CommonResult.error(NOT_IMPLEMENTED.getCode(), "[工作流模块 yudao-module-bpm - 已禁用][参考 https://doc.iocoder.cn/bpm/ 开启]"); - } - - // 情况二:正常情况下的 404 log.warn("[noHandlerFoundExceptionHandler]", ex); return CommonResult.error(NOT_FOUND.getCode(), String.format("请求地址不存在:%s", ex.getRequestURL())); } diff --git a/yudao-server/src/main/java/cn/iocoder/yudao/server/controller/DefaultController.java b/yudao-server/src/main/java/cn/iocoder/yudao/server/controller/DefaultController.java new file mode 100644 index 000000000..14946218a --- /dev/null +++ b/yudao-server/src/main/java/cn/iocoder/yudao/server/controller/DefaultController.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.server.controller; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_IMPLEMENTED; + +/** + * 默认 Controller,解决部分 module 未开启时的 404 提示。 + * 例如说,/bpm/** 路径,工作流 + * + * @author 芋道源码 + */ +@RestController +public class DefaultController { + + @RequestMapping("/admin-api/bpm/**") + public CommonResult bpm404() { + return CommonResult.error(NOT_IMPLEMENTED.getCode(), + "[工作流模块 yudao-module-bpm - 已禁用][参考 https://doc.iocoder.cn/bpm/ 开启]"); + } + +} diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 87f781091..7918d443c 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -17,8 +17,8 @@ spring: mvc: pathmatch: matching-strategy: ANT_PATH_MATCHER # 解决 SpringFox 与 SpringBoot 2.6.x 不兼容的问题,参见 SpringFoxHandlerProviderBeanPostProcessor 类 - throw-exception-if-no-handler-found: true # 404 错误时抛出异常,方便统一处理 - static-path-pattern: /static/** # 静态资源路径; 注意:如果不配置,则 throw-exception-if-no-handler-found 不生效!!! +# throw-exception-if-no-handler-found: true # 404 错误时抛出异常,方便统一处理 +# static-path-pattern: /static/** # 静态资源路径; 注意:如果不配置,则 throw-exception-if-no-handler-found 不生效!!! TODO 芋艿:不能配置,会导致 swagger 不生效 # Jackson 配置项 jackson: