【发布时间】:2015-12-17 05:36:03
【问题描述】:
我一直试图在以下 Spring 集成流程中找出循环引用的问题。
我正在为 entityManagerFactory 和 transactionManager bean 使用 Spring Boot 自动配置。
这是具有两个 jpa:updating-outbound-gateway 的集成上下文,它从两个不同的通道读取消息并将响应发送到一个公共通道。
<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 ..>
flow,应用程序运行良好。任何 cmets 或建议将不胜感激。
【问题讨论】:
-
您只需要删除 1 个网关吗?或两者?你能发布一个演示问题的小应用程序(例如在 github 上)吗?
-
我只需要删除一个。删除任何一个网关,应用程序运行正常。
-
哪一个重要吗?
-
我想知道
errorMessageUpdatingGateway是什么...我们在您的配置中没有看到它的定义。 -
我已经能够在本地复制它。奇怪的情况:当我们有多个
entity-manager-factory="entityManagerFactory"使用时,我们会失败。正在调查...
标签: java hibernate spring-boot spring-integration spring-data-jpa