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

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

问题描述

我有一个使用Spring的JPA和JTA的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天全站免登陆