gpt4 book ai didi

java - Spring jpa :inbound-channel-adapter configuration

转载 作者:太空宇宙 更新时间:2023-11-04 11:15:31 33 4
gpt4 key购买 nike

我尝试使用多个 jpa:inbound-channel-adapter。但是我有一个问题。当我添加两个入站 channel 适配器时,只有最后一个起作用。例如,有两个入站 channel ,我们现在将它们称为 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" />

我不明白问题出在哪里。你可以帮帮我吗?

编辑:我解决了问题。我向服务激活器类添加接口(interface),然后问题就解决了。

最佳答案

好的。这是一个错误。请参阅 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它们确实是同一个对象。

关于java - Spring jpa :inbound-channel-adapter configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45500287/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com