java - 在骆驼引导路线中使用 Spring-Boot @ControllerAdvice
问题描述
apache camel-boot 中是否有使用 Spring-Boot @ControllerAdvice 作为错误处理程序而不是 defaultErrorHandler 的实现?
我试图在路由类中包含@ExceptionHandler,但它似乎在 apache camel route configure() 中不适用/无效。
public class PersonRoute extends RouteBuilder {
@Override
public void configure() {
// JSON Rest
rest("/person")
.consumes(MediaType.APPLICATION_JSON_VALUE)
.produces(MediaType.APPLICATION_JSON_VALUE)
.post("/getPerson").type(Person.class).route().id("Get Person Route")
.to("bean-validator://x")
.to("{{route.getPerson}}")
.end();
from("{{route.getPerson}}")
.log("get Person request: ${body}")
.bean(PersonService.class, "getPerson(${body})");
}
@ExceptionHandler(Exception.class)
public final ResponseEntity<String> globalExceptionHandler(Exception e){
return new ResponseEntity<>(e.toString(), HttpStatus.BAD_REQUEST);
}
}
我是否需要向 camelContext 注入或附加某些内容才能使用@ControllerAdvice 或@ExceptionHandler?
解决方案
推荐阅读
- javascript - Node.js请求正文参数返回null,但请求查询有效
- .net-core - Dotnet Core url 显示
- python - 无法在 spyder 中安装软件包
- api - 具有自定义匹配功能的专用虚幻引擎服务器
- r - 如何在 R 中基于 Levels 绘制条形图?
- python - 如何将numpy数组中的值添加到python字典
- java - Apache JMeter 异常 NoSuchMethodError
- mongodb - 如何在 mongodb 中动态更改整个对象(包括数组)?
- jenkins - 詹金斯管道更新GitlabCommitStatus 不起作用
- python - Python,将请求离线安装为.whl不起作用