首页 > 解决方案 > 在骆驼引导路线中使用 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?

标签: javaspring-booterror-handlingspring-camel

解决方案


推荐阅读