繁体   English   中英

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

[英]Spring jpa:inbound-channel-adapter configuration

我尝试使用多个jpa:inbound-channel-adapter。 但是我有一个问题。 当我添加两个inbound-channel-adapter时,只有最后一个有效。 例如,有两个入站通道,我们现在称它们为x和y。 如果我先将x然后将y写入application.xml文件,则只有y有效。 如果先写y,那么只有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" />

我不明白问题是什么。 你可以帮帮我吗?

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

好。 这是一个错误。 参见JIRA: https : //jira.spring.io/browse/INT-4325

因此,解决您的问题,您必须为这些<int-jpa:inbound-channel-adapter>定义定义唯一的id

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM