2016-07-04 71 views
1

我是Spring Integration的新手,我試圖使用Java DSL配置來指定一個使用具有@Aggregator的類GroupPublishAggregator的聚合消息的流,@ReleaseStrategy ,和@CorrelationStrategy註解。嘗試通過@CorrelationStrategy註釋使用bean時,出現「空關聯不允許」

我懷疑我在配置中犯了一個新手錯誤,因爲當聚合器收到消息時我看到的是「java.lang.IllegalStateException:不允許空關聯,也許CorrelationStrategy失敗?如果我調試框架代碼,我發現AbstractCorrelatingMessageHandler正在調用默認的org.springframework.integration.aggregator.HeaderAttributeCorrelationStrategy而不是我的策略。

配置代碼如下:

@Bean 
public GroupPublishAggregator publishAggregator() { 
    // This class has methods with @Aggregator, @ReleaseStrategy, 
    // and @CorrelationStrategy annotations. 
    return new GroupPublishAggregator(); 
} 

@Bean 
public IntegrationFlow publish() { 
    return IntegrationFlows.from(this.inputChannel()) 
      .wireTap("monitor") 
      .aggregate(new Consumer<AggregatorSpec>() { 
       @Override 
       public void accept(AggregatorSpec aggregatorSpec) { 
        aggregatorSpec.processor(publishAggregator(), null); 
       } 
      }) 
      .get(); 
} 

回答

0

這是一個錯誤。將盡快修復:https://github.com/spring-projects/spring-integration-java-dsl/issues/93

同時爲你的解決方法是像使用CorrelationStrategyFactoryBeanReleaseStrategyFactoryBean@Bean,並分別與特定correlationStrategy(CorrelationStrategy correlationStrategy)releaseStrategy(ReleaseStrategy releaseStrategy)

對於那些FactoryBean s,我們不會撥打afterPropertiesSet()的問題。

+0

感謝您確認它應該工作。我通過回退到XML配置並指定策略引用和方法來解決此問題。 – nerff

+0

我已經驗證了您的解決方法的一個版本,現在可以在沒有XML配置的情況下運行,謝謝。我的'@ Bean'方法創建一個'CorrelationStrategyFactoryBean',用我的策略調用'setTarget()'方法,調用'afterPropertiesSet()'方法強制默認策略被覆蓋,並返回getObject的結果()'方法。 – nerff

相關問題