gpt4 book ai didi

java - @Header 注释未按预期工作

转载 作者:行者123 更新时间:2023-12-01 16:03:49 27 4
gpt4 key购买 nike

我正在开发一个 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)

我做错了什么?

最佳答案

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

这样就解决了。

关于java - @Header 注释未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3139713/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com