Commit 969b9c3458cead11e4feb77b52f4e0236b8bdf2c
1 parent
f6420e30
修复 swagger 404 的问题
Showing
3 changed files
with
26 additions
and
8 deletions
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 { |
| 168 | 168 | */ |
| 169 | 169 | @ExceptionHandler(NoHandlerFoundException.class) |
| 170 | 170 | public CommonResult<?> noHandlerFoundExceptionHandler(HttpServletRequest req, NoHandlerFoundException ex) { |
| 171 | - // 情况一:部分功能未开启 | |
| 172 | - if (req.getRequestURI().contains("/bpm/")) { | |
| 173 | - return CommonResult.error(NOT_IMPLEMENTED.getCode(), "[工作流模块 yudao-module-bpm - 已禁用][参考 https://doc.iocoder.cn/bpm/ 开启]"); | |
| 174 | - } | |
| 175 | - | |
| 176 | - // 情况二:正常情况下的 404 | |
| 177 | 171 | log.warn("[noHandlerFoundExceptionHandler]", ex); |
| 178 | 172 | return CommonResult.error(NOT_FOUND.getCode(), String.format("请求地址不存在:%s", ex.getRequestURL())); |
| 179 | 173 | } | ... | ... |
yudao-server/src/main/java/cn/iocoder/yudao/server/controller/DefaultController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.server.controller; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 5 | +import org.springframework.web.bind.annotation.RestController; | |
| 6 | + | |
| 7 | +import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_IMPLEMENTED; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 默认 Controller,解决部分 module 未开启时的 404 提示。 | |
| 11 | + * 例如说,/bpm/** 路径,工作流 | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@RestController | |
| 16 | +public class DefaultController { | |
| 17 | + | |
| 18 | + @RequestMapping("/admin-api/bpm/**") | |
| 19 | + public CommonResult<Boolean> bpm404() { | |
| 20 | + return CommonResult.error(NOT_IMPLEMENTED.getCode(), | |
| 21 | + "[工作流模块 yudao-module-bpm - 已禁用][参考 https://doc.iocoder.cn/bpm/ 开启]"); | |
| 22 | + } | |
| 23 | + | |
| 24 | +} | ... | ... |
yudao-server/src/main/resources/application.yaml
| ... | ... | @@ -17,8 +17,8 @@ spring: |
| 17 | 17 | mvc: |
| 18 | 18 | pathmatch: |
| 19 | 19 | matching-strategy: ANT_PATH_MATCHER # 解决 SpringFox 与 SpringBoot 2.6.x 不兼容的问题,参见 SpringFoxHandlerProviderBeanPostProcessor 类 |
| 20 | - throw-exception-if-no-handler-found: true # 404 错误时抛出异常,方便统一处理 | |
| 21 | - static-path-pattern: /static/** # 静态资源路径; 注意:如果不配置,则 throw-exception-if-no-handler-found 不生效!!! | |
| 20 | +# throw-exception-if-no-handler-found: true # 404 错误时抛出异常,方便统一处理 | |
| 21 | +# static-path-pattern: /static/** # 静态资源路径; 注意:如果不配置,则 throw-exception-if-no-handler-found 不生效!!! TODO 芋艿:不能配置,会导致 swagger 不生效 | |
| 22 | 22 | |
| 23 | 23 | # Jackson 配置项 |
| 24 | 24 | jackson: | ... | ... |