gpt4 book ai didi

java - Spring Integration 和 JPA 更新出站网关时出现循环引用错误

转载 作者:行者123 更新时间:2023-11-30 08:43:21 27 4
gpt4 key购买 nike

我一直在尝试找出以下 spring 集成流程中循环引用的问题。

我正在为 entityManagerFactory 和 transactionManager bean 使用 Spring Boot 自动配置。

这是具有两个 jpa:updating-outbound-gateway 的集成上下文,它从两个不同的 channel 读取消息并将响应发送到一个公共(public) channel 。

<int-jms:message-driven-channel-adapter
id="jmsListener" connection-factory="connectionFactory"
channel="queueChannel" destination="queueName"
error-channel="errorChannel"/>

<int:chain input-channel="queueChannel" output-channel="dbChannel">
....
// more stuff
....
</int:chain>

<int-jpa:updating-outbound-gateway id="updatingGateway1" request-channel="dbChannel" entity-manager-factory="entityManagerFactory" entity-class="com.example.MyMessage1" persist-mode="PERSIST" reply-channel="reportChannel" reply-timeout="5000">
<int-jpa:transactional transaction-manager="transactionManager" propagation="REQUIRED"/>
</int-jpa:updating-outbound-gateway>

<int:channel id="errorChannel"/>

<int-jpa:updating-outbound-gateway id="updatingGateway2" request-channel="errorChannel" entity-manager-factory="entityManagerFactory" entity-class="com.example.MyMessage2" persist-mode="PERSIST" reply-channel="reportChannel" reply-timeout="5000">
<int-jpa:transactional transaction-manager="transactionManager" propagation="REQUIRED"/>
</int-jpa:updating-outbound-gateway>

<int:channel id="reportChannel"/>
<int:logging-channel-adapter channel="reportChannel" expression="payload"/>

运行应用程序时出现以下错误。

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'dataSourceInitializerPostProcessor':
Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private org.springframework.beans.factory.BeanFactory

org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.beanFactory;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.integration.jpa.outbound.JpaOutboundGatewayFactoryBean#0':
Cannot resolve reference to bean 'updatingGateway2.jpaExecutor'
while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'updatingGateway2.jpaExecutor':
Cannot resolve reference to bean 'entityManagerFactory'
while setting constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration':
Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private javax.sql.DataSource
org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource;
nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'org.springframework.integration.jpa.outbound.JpaOutboundGatewayFactoryBean#1':
Cannot resolve reference to bean 'updatingGateway1.jpaExecutor' while
setting constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'updatingGateway1.jpaExecutor':
Cannot resolve reference to bean 'entityManagerFactory' while setting
constructor argument; nested exception is
org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'entityManagerFactory': Requested bean
is currently in creation: Is there an unresolvable circular reference?

但是如果我删除其中一个

<int-jpa:updating-outbound-gateway ..> 

流程,应用程序运行良好。如有任何意见或建议,我们将不胜感激。

最佳答案

好吧,我认为我们确实遇到了这个问题:https://jira.spring.io/browse/INT-3857 : CTOR 注入(inject)导致 dep 为 FactoryBean 过早实例化。

不幸的是,我们刚刚发布了 SI-4.2.4,因此 JpaOutboundGatewayFactoryBean 的修复将在稍后的某个地方进行。

与此同时,您可以尝试将其用作解决方法吗?

<bean id="jpaOperations" class="org.springframework.integration.jpa.core.DefaultJpaOperations">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<int-jpa:updating-outbound-gateway jpa-operations="jpaOperations" />

代替 entity-manager-factory="entityManagerFactory"

有关此事的 JIRA 票证:https://jira.spring.io/browse/INT-3916 .

关于java - Spring Integration 和 JPA 更新出站网关时出现循环引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34327330/

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