如何使用Spring Integration DSL在子流路由中转换String

时间:2019-10-06 16:18:08

标签: java spring kotlin spring-integration spring-integration-dsl

我在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)

1 个答案:

答案 0 :(得分:1)

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

作为一种解决方法,我建议使用filter()代替transform(),因为PayloadMethodArgumentResolver的{​​{1}}不允许空有效载荷< / em>默认情况下:

InvocableHandlerMethod

更新

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