Spring Integration和JPA更新出站网关

时间:2015-12-17 05:36:03

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

我一直试图在下面的Spring集成流程中找出循环引用的问题。

我正在为entityManagerFactory和transactionManager bean使用Spring Boot Auto Configuration。

以下是两个jpa的集成上下文:updates-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 ..> 

流程,应用程序运行正常。任何意见或建议将不胜感激。

0 个答案:

没有答案