2017-08-04 123 views
1

我嘗試使用多個jpa:入站通道適配器。但是我有一個問題。當我添加兩個入站通道適配器時,只有最後一個工作。例如,現在有兩個入站通道,我們稱它們爲x和y。如果我先寫x然後寫y到application.xml文件,那麼只有y有效。如果先寫y,那麼x只有x有效。這裏是xml配置,Spring jpa:入站通道適配器配置

<int:channel id="emailChannel" /> 
<int-jpa:inbound-channel-adapter 
    channel="emailChannel" entity-manager-factory="entityManagerFactory" 
    auto-startup="true" 
    jpa-query="select slt from Email slt where slt.mailStatus = 'NEW'" 
    expect-single-result="false" delete-after-poll="false"> 
    <int:poller fixed-rate="10000" > 
     <int:transactional propagation="REQUIRED" 
      transaction-manager="transactionManager" /> 
    </int:poller> 
</int-jpa:inbound-channel-adapter> 
<int:service-activator input-channel="emailChannel" ref="EmailSenderEndPoint" method="sendEmail" /> 


<int:channel id="msgChannel" /> 
<int-jpa:inbound-channel-adapter 
    channel="msgChannel" entity-manager-factory="entityManagerFactory" 
    auto-startup="true" 
    jpa-query="select rm from Msg rm where rm.isApproved= '1' " 
    expect-single-result="false" delete-after-poll="false"> 
    <int:poller fixed-rate="30000"> 
     <int:transactional propagation="REQUIRED" 
      transaction-manager="transactionManager" /> 
    </int:poller> 
</int-jpa:inbound-channel-adapter> 
<int:service-activator input-channel="msgChannel" ref="MsgSenderEndPoint" method="sendMsg" /> 

在上例中,只有msgChannel工作。但是,如果我改變如下,只有emailChannel的作品。

<int:channel id="msgChannel" /> 
<int-jpa:inbound-channel-adapter 
    channel="msgChannel" entity-manager-factory="entityManagerFactory" 
    auto-startup="true" 
    jpa-query="select rm from Msg rm where rm.isApproved= '1' " 
    expect-single-result="false" delete-after-poll="false"> 
    <int:poller fixed-rate="30000"> 
     <int:transactional propagation="REQUIRED" 
      transaction-manager="transactionManager" /> 
    </int:poller> 
</int-jpa:inbound-channel-adapter> 
<int:service-activator input-channel="msgChannel" ref="MsgSenderEndPoint" method="sendMsg" /> 


<int:channel id="emailChannel" /> 
<int-jpa:inbound-channel-adapter 
    channel="emailChannel" entity-manager-factory="entityManagerFactory" 
    auto-startup="true" 
    jpa-query="select slt from Email slt where slt.mailStatus = 'NEW'" 
    expect-single-result="false" delete-after-poll="false"> 
    <int:poller fixed-rate="10000" > 
     <int:transactional propagation="REQUIRED" 
      transaction-manager="transactionManager" /> 
    </int:poller> 
</int-jpa:inbound-channel-adapter> 
<int:service-activator input-channel="emailChannel" ref="EmailSenderEndPoint" method="sendEmail" /> 

我不明白問題是什麼。你可以幫幫我嗎?

編輯:我解決了這個問題。我將接口添加到服務激活器類,然後解決問題。

+0

什麼是Spring集成版本? –

回答

0

好的。這是一個錯誤。參見JIRA:https://jira.spring.io/browse/INT-4325

所以,解決您的問題,你必須定義獨特id對於那些<int-jpa:inbound-channel-adapter>定義:

<int-jpa:inbound-channel-adapter id="msgJpaAdapter" 
channel="msgChannel" entity-manager-factory="entityManagerFactory" 

... 

<int-jpa:inbound-channel-adapter id="emailJpaAdapter" 
channel="emailChannel" entity-manager-factory="entityManagerFactory" 

UPDATE

我們有一個配置測試用例:

<int-jpa:inbound-channel-adapter id="jpaInboundChannelAdapter1" 
     entity-manager-factory="entityManagerFactory" 
     entity-class="org.springframework.integration.jpa.test.entity.StudentDomain" 
     expect-single-result="true" 
     parameter-source="jpaParameterSource" 
     channel="out"> 
    <int:poller fixed-rate="5000"/> 
</int-jpa:inbound-channel-adapter> 

<int-jpa:inbound-channel-adapter id="jpaInboundChannelAdapter2" 
    entity-manager-factory="entityManagerFactory" 
    entity-class="org.springframework.integration.jpa.test.entity.StudentDomain" 
    max-results="13" 
    delete-after-poll="true" 
    flush-after-delete="true" 
    channel="out"> 
    <int:poller fixed-rate="5000"/> 
</int-jpa:inbound-channel-adapter> 

像:

JpaExecutor jpaExecutor1 = context.getBean("jpaInboundChannelAdapter1.jpaExecutor", JpaExecutor.class); 
    JpaExecutor jpaExecutor2 = context.getBean("jpaInboundChannelAdapter2.jpaExecutor", JpaExecutor.class); 
    assertNotNull(jpaExecutor1); 
    assertNotNull(jpaExecutor2); 

    assertNotSame(jpaExecutor1, jpaExecutor2); 

但是在空的情況下id它們確實是同一個對象。

+0

我定義了id,但它無法幫助我。我發現只有解決方案將接口添加到service-activator引用類。 – Zapateus

+0

您是否針對不同的通道適配器定義使用不同的ID? –

+0

在我的答案中查看更新。 –

相關問題