Spring jpa:入站通道适配器配置

时间:2017-08-04 07:07:47

标签: java spring spring-data-jpa spring-integration

我尝试使用多个jpa:inbound-channel-adapter。但是我有一个问题。当我添加两个入站通道适配器时,只有最后一个工作。例如,有两个入站通道,我们现在将它们称为x和y。如果我先写x然后y写入application.xml文件,只有y工作。如果先写y然后x只有x工作。这是xml配置,

    <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" />

我无法理解问题所在。你可以帮帮我吗?

编辑:我解决了这个问题。我将接口添加到服务激活器类,然后解决了问题。

1 个答案:

答案 0 :(得分: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"

<强>更新

我们有一个配置测试用例:

<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的情况下,它们确实是同一个对象。