Spring Integration Null相关不允许。也许CorrelationStrategy失败了吗?

时间:2017-09-08 19:35:08

标签: spring-integration

我收到错误`不允许空相关。也许CorrelationStrategy失败了吗?

这个论坛主题似乎用下面的内容来解决它,但是这种方法对我不起作用,http://forum.spring.io/forum/spring-projects/integration/102054-aggregator-correlation-strategy-failing

我的理解是inbound-streaming-channel-adapter将FILE_NAME作为标题值,我想加入。

    <int-ftp:inbound-streaming-channel-adapter
    auto-startup="true" id="ftpListener" channel="ftpChannel"
    session-factory="ftpSessionFactory" remote-directory="/export/home/udyj"
    filename-pattern="test1.txt">
    <integration:poller fixed-rate="5000"
        max-messages-per-poll="-1" />
</int-ftp:inbound-streaming-channel-adapter>

<int-ftp:inbound-streaming-channel-adapter
    auto-startup="true" id="ftpListener2" channel="ftpChannel"
    session-factory="ftpSessionFactory" remote-directory="/export/home/udyj"
    filename-pattern="test2.txt">
    <integration:poller fixed-rate="5000"
        max-messages-per-poll="-1" />
</int-ftp:inbound-streaming-channel-adapter>

<bean id="correlationStrategy"
    class="org.springframework.integration.aggregator.HeaderAttributeCorrelationStrategy">
    <constructor-arg value="FILE_NAME.substring(0,3)" />
</bean>
<integration:aggregator id="nuggetAggregator"
    input-channel="ftpChannel" output-channel="sendMQDistributionChannel"
    correlation-strategy="correlationStrategy">
</integration:aggregator>

1 个答案:

答案 0 :(得分:1)

看,你说HeaderAttributeCorrelationStrategy,肯定期望得到一个标题名称。但同时你将标题名称指定为FILE_NAME.substring(0,3),它看起来更像一个表达式。你得到null因为实际上没有这样的标题。

如果要评估表达式,请考虑改为使用ExpressionEvaluatingCorrelationStrategy

<bean id="correlationStrategy"
    class="org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy">
    <constructor-arg value="headers.file_name.substring(0,3)" />
</bean>