Apache Camel 和 Springboot - 404 状态 - 当客户尝试到达无效/未定义的端点时,响应正文为空白

问题描述 投票:0回答:1

我正在尝试让自定义 json 响应正文向客户表明他们尝试到达无效路由。当他们在请求 ex 时缺少参数时。 localhost:8080/hello//is/my/path 与正确的路径 localhost:8080/hello/this/is/my/path 骆驼给出 404 状态,但响应为空白。我似乎无法添加自定义响应,因为骆驼甚至不读取我的代码。它只是给出 404 状态,甚至没有例外。请帮忙。

我尝试添加全局异常处理程序以及默认路由,但这些代码都没有被读取。

java spring-boot apache apache-camel
1个回答
0
投票

您可以尝试使用以下命令创建异常处理程序吗 @ExceptionHandler({NoHandlerFoundException.class}) 注解然后添加 @EnableWebMvc 到您的主应用程序类,然后在 application.yml 中启用它应该可以解决您的问题 spring.mvc.throw-exception-if-no-handler-found=true

© www.soinside.com 2019 - 2024. All rights reserved.