@Header 注释未按预期工作

发布于 2024-09-07 19:47:05 字数 1825 浏览 5 评论 0原文

我正在开发一个 spring 集成项目(1.0.2),但无法让 @Header 注释工作。

这是我的服务激活器:

@Component
public class MyTransformer {
    @ServiceActivator(inputChannel = "inChannel", outputChannel = "outChannel")
    public String transform(final Message<?> message,
                            @Header(value = "eventId") final Long id,
                            @Header(value = "error", required = false) final Throwable throwable) {
        return throwable == null
                ? "event [" + eventId +"]"
                : "event [" + eventId +"] error: " + throwable.getMessage();
    }
}

这是错误消息:

Caused by: java.lang.IllegalArgumentException: Wrong number of arguments. Expected types {class java.lang.Object, class java.lang.Long, class java.lang.Throwable}, but received values {[Payload=parp][Headers={eventId=888Foo, error=java.lang.IllegalArgumentException: Invalid message content parp, springintegration_timestamp=1277803938244, springintegration_id=726d0769-bd27-4d95-a9ea-640c1f807065}]}.
    at org.springframework.integration.util.DefaultMethodInvoker.invokeMethod(DefaultMethodInvoker.java:71)
    at org.springframework.integration.handler.MessageMappingMethodInvoker.doInvokeMethod(MessageMappingMethodInvoker.java:160)
    at org.springframework.integration.handler.MessageMappingMethodInvoker.invokeMethod(MessageMappingMethodInvoker.java:107)
    at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:49)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:91)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:59)

我做错了什么?

I am working on a spring integration project (1.0.2) and can't get the @Header annotation to work.

Here's my service activator:

@Component
public class MyTransformer {
    @ServiceActivator(inputChannel = "inChannel", outputChannel = "outChannel")
    public String transform(final Message<?> message,
                            @Header(value = "eventId") final Long id,
                            @Header(value = "error", required = false) final Throwable throwable) {
        return throwable == null
                ? "event [" + eventId +"]"
                : "event [" + eventId +"] error: " + throwable.getMessage();
    }
}

Here's the error message:

Caused by: java.lang.IllegalArgumentException: Wrong number of arguments. Expected types {class java.lang.Object, class java.lang.Long, class java.lang.Throwable}, but received values {[Payload=parp][Headers={eventId=888Foo, error=java.lang.IllegalArgumentException: Invalid message content parp, springintegration_timestamp=1277803938244, springintegration_id=726d0769-bd27-4d95-a9ea-640c1f807065}]}.
    at org.springframework.integration.util.DefaultMethodInvoker.invokeMethod(DefaultMethodInvoker.java:71)
    at org.springframework.integration.handler.MessageMappingMethodInvoker.doInvokeMethod(MessageMappingMethodInvoker.java:160)
    at org.springframework.integration.handler.MessageMappingMethodInvoker.invokeMethod(MessageMappingMethodInvoker.java:107)
    at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:49)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:91)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:59)

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情徒 2024-09-14 19:47:05

当然,Event Id 应该是 String,而不是 Long。

这样就解决了。

Of course, Event Id should be a String, not a Long.

That fixes it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文