Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring集成和JPA事务_Spring_Spring Data Jpa_Spring Integration - Fatal编程技术网

Spring集成和JPA事务

Spring集成和JPA事务,spring,spring-data-jpa,spring-integration,Spring,Spring Data Jpa,Spring Integration,我使用Spring集成来接收XML形式的XMPP消息: <int-xmpp:inbound-channel-adapter id="xmppInboundAdapter" channel="xmppInbound" xmpp-connection="xmppConnection" auto-startup="true" /> <int:channel id="xmppInbound" /> <int:service-activator ref="messageRou

我使用Spring集成来接收XML形式的XMPP消息:

<int-xmpp:inbound-channel-adapter id="xmppInboundAdapter" channel="xmppInbound" xmpp-connection="xmppConnection" auto-startup="true" />
<int:channel id="xmppInbound" />
<int:service-activator ref="messageRouterService" input-channel="xmppInbound" />

我已经有了一些持久性特性,它可以工作(将消息存储在数据库中,将消息与数据库中的内容进行比较分析,…)

现在我有了一个方法,它需要是事务性的,因为我需要初始化与一个实体相关的两个集合,所以第二个集合是通过调用一个方法来初始化的


这在JUnit中工作得很好,但是我需要做什么才能使它在主代码中工作呢?我是否可以将@Transactional放在任何级别,或者它是否需要放在整个流程的根目录中,或者甚至需要在入站适配器中以某种方式声明?

如果您在JPA和数据库方面所做的艰苦工作真的只是在提到的
messageRouterService
中,然后,用
@Transactional
注释标记该服务方法,并正确地参考您的
JpaTransactionManager
就足够了


如果认为整个流程是事务性的,那么就不可能从
开始,因为没有可注入
TransactionInterceptor
的钩子。但是,您可以使用
TransactionInterceptorBuilder(true)
生成一个
TransactionHandleMessageAdvice
,它将通过其
包装整个子流,从已通知的端点开始:

您是否可以更精确地说“正确地参考您的JpaTransactionManager”?我在一个配置类上有一个“@EnableTransactionManagement”注释,这个类声明了一个jpaTransactionManager bean,你认为我需要更多吗?不,这就足够了。我更担心的是,您可能会有多个
TransactionManager
。。