Spring JTA TransactionManager 配置:同时支持 Tomcat 和 JBoss [英] Spring JTA TransactionManager config: Supporting both Tomcat and JBoss

查看:27
本文介绍了Spring JTA TransactionManager 配置:同时支持 Tomcat 和 JBoss的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 JPA 和 JTA 和 Spring 的 Web 应用程序.我想同时支持 JBoss 和 Tomcat.在JBoss上运行时,我想用JBoss自带的TransactionManager,在Tomcat上运行时,我想用JOTM.

I have a web application using JPA and JTA with Spring. I would like to support both JBoss and Tomcat. When running on JBoss, I'd like to use JBoss' own TransactionManager, and when running on Tomcat, I'd like to use JOTM.

我有两种方案都可以使用,但我现在发现对于这两种情况,我似乎需要两个单独的 Spring 配置.使用 JOTM,我需要使用 Spring 的 JotmFactoryBean:

I have both scenarios working, but I now find that I seem to need two separate Spring configurations for the two cases. With JOTM, I need to use Spring's JotmFactoryBean:

<bean id="transactionManager" 
 class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="userTransaction">
        <bean class="org.springframework.transaction.jta.JotmFactoryBean"/>
    </property>
</bean>

不过,在 JBoss 中,我只需要从 JNDI 获取TransactionManager":

In JBoss, though, I just need to fetch "TransactionManager" from JNDI:

<bean id="transactionManager" 
 class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager">
        <bean class="org.springframework.jndi.JndiObjectFactoryBean">
             <property name="resourceRef" value="true" />
             <property name="jndiName" value="TransactionManager" />
             <property name="expectedType" 
               value="javax.transaction.TransactionManager" />
        </bean>
    </property>
</bean>

有没有办法配置它,以便使用适当的 TransactionManager - JBoss 或 JOTM - 而不需要两个不同的配置文件?

Is there a way to configure this so that the appropriate TransactionManager - JBoss or JOTM - is used, without the need for two different configuration files?

推荐答案

我想你已经错过了 JNDI 的重点.JNDI 几乎是为解决您遇到的问题而编写的!

I think you have missed the point of JNDI. JNDI was pretty much written to solve the problem you have!

我认为您可以将其提升一个级别,因此根据您的情况,不要使用userTransaction"或JNDI 的transactionManager".为什么不将JtaTransactionManager"添加到 JNDI.这样你就可以将配置推送到 JNDI 应该在的地方,而不是创建更多的配置文件 [就像没有足够的配置文件 ;) ].

I think you can take it up a level, so instead of using the "userTransaction" or "transactionManager from JNDI" depending on your situation. Why not add the "JtaTransactionManager" to JNDI. That way you push the configuration to the JNDI where it is supposed to be instead of creating even more configuration files [ like there aren't enough already ;) ].

这篇关于Spring JTA TransactionManager 配置:同时支持 Tomcat 和 JBoss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆