gpt4 book ai didi

java - 如何使用 spring 集成 dsl 转换子流路由中的字符串

转载 作者:行者123 更新时间:2023-12-02 09:27:18 26 4
gpt4 key购买 nike

我在 spring 集成中使用路由与转换编写了一个非常简单的示例,但它是否给出了 SpelEvaluationException

代码网关:

@MessagingGateway
@Component
interface ApiGateway {

@Gateway(requestChannel = "integrateAttributeChannel")
fun integrateAttributes(message: String)

}

我的流程:

IntegrationFlows
.from("integrateAttributeChannel")
.route<String, Boolean>({ sellerId -> sellerId.isBlank() },
{ m ->
m.subFlowMapping(true) { sf ->
sf.transform<String, String> { t -> t.toUpperCase() }
}
m.subFlowMapping(false) { sf ->
sf.transform<String, String> { t -> t.reversed() }
}
})
.handle { t -> println(t) }
.get()

异常跟踪:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method transform(java.lang.String) cannot be found on type br.com.gubee.config.AttributeFlow$flow$2$2$1
at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:225)
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:134)
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:54)
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:390)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:90)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:114)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:365)
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:172)
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:160)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.invokeExpression(MessagingMethodInvokerHelper.java:664)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.invokeHandlerMethod(MessagingMethodInvokerHelper.java:655)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:491)
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:362)
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:106)
at org.springframework.integration.transformer.AbstractMessageProcessingTransformer.transform(AbstractMessageProcessingTransformer.java:113)
at org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:109)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:123)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:162)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115)

最佳答案

当我们回退到 SpEL 调用时,它看起来像是一个错误,它只是找不到具有预期参数类型的方法来调用。请针对 Spring Integration 提出问题。即使使用常规 Java,我们也会遇到同样的问题,而不仅仅是 Kotlin。

作为一种解决方法,我建议使用 filter() 而不是 transform(),因为 PayloadMethodArgumentResolver 用于 默认情况下,InvocableHandlerMethod 不允许空负载:

if (isEmptyPayload(payload)) {
if (ann == null || ann.required()) {
String paramName = getParameterName(parameter);
BindingResult bindingResult = new BeanPropertyBindingResult(payload, paramName);
bindingResult.addError(new ObjectError(paramName, "Payload value must not be empty"));
throw new MethodArgumentNotValidException(message, parameter, bindingResult);
}

更新

我继续创建了一个问题:https://github.com/spring-projects/spring-integration/issues/3079

关于java - 如何使用 spring 集成 dsl 转换子流路由中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58259113/

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