java Spring jta-transaction-manager
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1963612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring jta-transaction-manager
提问by cometta
Using Spring:
使用弹簧:
can jta-transaction-manager use id as name so that I can pass it as REF to my service layer like below?
is tx:jta-transaction-manager can only be used for je22 container? I mean for Tomcat, I need to do it manually, like below:
<tx:jta-transaction-manager id="name_transactionmanager"/> <bean id="projectService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="name_transactionmanager"/> <property name="target"> <bean class="com.company.project.company.services.ServiceImpl" init-method="init"> <property name="HRappsdao" ref="HRappsdao"/> <property name="projectdao" ref="projectdao"/> </bean> </property> <property name="transactionAttributes"> <props> <prop key="store*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="bulkUpdate*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_SUPPORTS,readOnly</prop> </props> </property> </bean>
jta-transaction-manager 可以使用 id 作为名称,以便我可以将它作为 REF 传递给我的服务层,如下所示?
tx:jta-transaction-manager 是否只能用于 je22 容器?我的意思是对于Tomcat,我需要手动完成,如下所示:
<tx:jta-transaction-manager id="name_transactionmanager"/> <bean id="projectService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="name_transactionmanager"/> <property name="target"> <bean class="com.company.project.company.services.ServiceImpl" init-method="init"> <property name="HRappsdao" ref="HRappsdao"/> <property name="projectdao" ref="projectdao"/> </bean> </property> <property name="transactionAttributes"> <props> <prop key="store*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="bulkUpdate*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_SUPPORTS,readOnly</prop> </props> </property> </bean>
For question 2
对于问题 2
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction">
<bean class="org.springframework.transaction.jta.JotmFactoryBean"/>
</property>
</bean>
回答by Pascal Thivent
Can
tx:jta-transaction-manageruse id as name so that I can pass it as REF to my service layer like below?
可以
tx:jta-transaction-manager使用 id 作为名称,以便我可以将它作为 REF 传递给我的服务层,如下所示?
The <tx:jta-transaction-manager>exposes the transaction manager as a Bean in the Spring context with the name "transactionManager".
将<tx:jta-transaction-manager>事务管理器公开为 Spring 上下文中名为“ transactionManager”的 Bean 。
Can
tx:jta-transaction-manageronly be used with a J2EE container?
可以
tx:jta-transaction-manager只用一个J2EE容器中使用?
Quoting the Chapter 9. Transaction managementfrom the Spring documentation:
引用Spring 文档中的第 9 章事务管理:
Is an application server needed for transaction management?
The Spring Framework's transaction management support significantly changes traditional thinking as to when a J2EE application requires an application server.
In particular, you don't need an application server just to have declarative transactions via EJB. In fact, even if you have an application server with powerful JTA capabilities, you may well decide that the Spring Framework's declarative transactions offer more power and a much more productive programming model than EJB CMT.
Typically you need an application server's JTA capability only if you need to enlist multiple transactional resources, and for many applications being able to handle transactions across multiple resources isn't a requirement. For example, many high-end applications use a single, highly scalable database (such as Oracle 9i RAC). Standalone transaction managers such as Atomikos Transactionsand JOTMare other options. (Of course you may need other application server capabilities such as JMS and JCA.)
The most important point is that with the Spring Framework you can choose when to scale your application up to a full-blown application server. Gone are the days when the only alternative to using EJB CMT or JTA was to write code using local transactions such as those on JDBC connections, and face a hefty rework if you ever needed that code to run within global, container-managed transactions. With the Spring Framework, only configuration needs to change so that your code doesn't have to.
事务管理是否需要应用服务器?
Spring Framework 的事务管理支持显着改变了 J2EE 应用程序何时需要应用程序服务器的传统想法。
特别是,您不需要应用程序服务器来通过 EJB 进行声明性事务。事实上,即使您拥有具有强大 JTA 功能的应用程序服务器,您也很可能认为 Spring 框架的声明式事务提供了比 EJB CMT 更强大的功能和更高效的编程模型。
通常,只有在需要征用多个事务性资源时才需要应用程序服务器的 JTA 功能,并且对于许多应用程序而言,不需要能够跨多个资源处理事务。例如,许多高端应用程序使用单一的、高度可扩展的数据库(如 Oracle 9i RAC)。Atomikos Transactions和JOTM等独立事务管理器是其他选择。(当然,您可能需要其他应用程序服务器功能,例如 JMS 和 JCA。)
最重要的一点是,使用 Spring Framework,您可以选择何时将应用程序扩展为成熟的应用程序服务器。使用 EJB CMT 或 JTA 的唯一替代方法是使用本地事务(例如 JDBC 连接上的事务)编写代码,并且如果您需要该代码在全局容器管理的事务中运行,则需要大量返工的日子已经一去不复返了。使用 Spring 框架,只需要更改配置,您的代码就不必更改。
So, as explained in the third paragraph, if you want to work with multiple transactional resources, you'll need global transactions which involve a JTA capable application server. And JTA capable application servermeans a real J2EE container or a non J2EE container (like Tomcat) with a standalone transaction manager like Atomikos, JOTM, Bitronix, SimpleJTA, JBossTSor GeronimoTM/Jencks.
因此,如第三段所述,如果您想使用多个事务资源,您将需要涉及具有 JTA 功能的应用程序服务器的全局事务。支持JTA 的应用服务器意味着真正的 J2EE 容器或非 J2EE 容器(如 Tomcat),带有独立的事务管理器,如Atomikos、JOTM、Bitronix、SimpleJTA、JBossTS或GeronimoTM/Jencks。
FWIW, I've seen lots of complains about JOTM, I think that GeronimoTM/Jencks lacks of documentation, I can't really say anything about JBossTSArjunaTS (except that it's a rock solid product), SimpleJTA and Bitronix have both good documentation and Atomikos is an impressive product greatly documented too. Personally, I'd choose Bitronix or Atomikos.
FWIW,我看到很多关于 JOTM 的抱怨,我认为 GeronimoTM/Jencks 缺乏文档,我真的不能说JBossTSArjunaTS(除了它是一个坚如磐石的产品),SimpleJTA 和 Bitronix 都有很好的文档和Atomikos 是一个令人印象深刻的产品,也有大量记录。就个人而言,我会选择 Bitronix 或 Atomikos。
PS: Honestly, if this sounds like Chinese to you, you should maybe consider using a single database (if this is an option, go for it!) or consider using a real J2EE container like JBoss or GlassFish as I wrote in a previous answer. No offense but all this JTA stuff is not trivial and taking the JOTM path is not that simple if you don't really understand why you need it.
PS:老实说,如果这对你来说听起来像中文,你应该考虑使用单个数据库(如果这是一个选项,那就去吧!) . 无意冒犯,但所有这些 JTA 东西都不是微不足道的,如果您不真正理解为什么需要它,那么走 JOTM 路径也不是那么简单。

