Spring jta 事务管理器

发布于 2024-08-16 14:19:46 字数 1859 浏览 6 评论 0原文

使用 Spring

  1. jta-transaction-manager 可以使用 id 作为名称,以便我可以将它作为 REF 传递到我的服务层,如下所示?

  2. tx:jta-transaction-manager 只能用于 je22 容器吗?我的意思是对于 Tomcat,我需要手动执行此操作,如下所示:

    ;
    
        
            <属性名称=“事务管理器”
                      ref="name_transactionmanager"/>
            <属性名称=“目标”>
                <豆类
                  类=“com.company.project.company.services.ServiceImpl”
                  init-method =“初始化”>
                     <财产
                       名称=“HRappsdao”
                       ref="HRappsdao"/>>
                     <财产
                       名称=“projectdao”
                       ref =“projectdao”/>
                
            
            <属性名称=“transactionAttributes”>
                <道具>
                    PROPAGATION_REQUIRED;
                    PROPAGATION_REQUIRED;
                    PROPAGATION_REQUIRED;
                    PROPAGATION_REQUIRED;
                    PROPAGATION_SUPPORTS,readOnly;
                
            
        
    

对于问题 2

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

Using Spring:

  1. can jta-transaction-manager use id as name so that I can pass it as REF to my service layer like below?

  2. 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>
    

For question 2

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2024-08-23 14:19:46

可以 tx:jta-transaction-manager 使用 id 作为名称,以便我可以将其作为 REF 传递到我的服务层,如下所示?

将事务管理器公开为 Spring 上下文中的 Bean,名称为“transactionManager”。

tx:jta-transaction-manager 只能与 J2EE 容器一起使用吗?

引用Spring文档中的第9章事务管理 :

事务管理是否需要应用程序服务器?

Spring框架的事务
管理层大力支持
改变传统思维
当 J2EE 应用程序需要
应用服务器。

特别是,您不需要
应用服务器只需具备
通过 EJB 的声明式事务。在
事实上,即使你有一个应用程序
服务器具有强大的JTA功能,
你很可能会决定春天
框架的声明式事务
提供更多的力量和更多
比 EJB 更高效的编程模型
CMT。

通常您需要一个应用程序
服务器的 JTA 功能仅当您
需要征集多个交易
资源,以及许多应用程序
能够处理交易
跨多个资源不是
要求。例如,许多
高端应用使用单一,
高度可扩展的数据库(例如
Oracle 9i RAC)。独立交易
管理器,例如 Atomikos Transactions
JOTM 是其他选项。 (当然
您可能需要其他应用程序服务器
JMS 和 JCA 等功能。)

最重要的一点是
您可以选择的 Spring 框架
何时将您的应用程序扩展到
成熟的应用程序服务器。走了
是唯一选择的日子
使用 EJB CMT 或 JTA 的方法是编写
使用本地事务的代码,例如
那些在 JDBC 连接上的,并面临
如果你需要的话,需要大量返工
在全局范围内运行的代码,
容器管理的事务。和
仅 Spring 框架
配置需要更改,以便
您的代码不必这样做。

因此,正如第三段中所解释的,如果您想要使用多个事务资源,您将需要涉及支持 JTA 的应用程序服务器的全局事务。支持 JTA 的应用服务器意味着真正的 J2EE 容器或非 J2EE 容器(如 Tomcat),具有独立的事务管理器(如 AtomikosJOTMBitronixSimpleJTAJBossTSGeronimoTM/Jencks

FWIW,我看到很多关于 JOTM 的抱怨,我认为 GeronimoTM/Jencks 缺乏文档,我真的不能说任何关于 JBossTSArjunaTS (除了它是一个坚如磐石的产品),SimpleJTA Bitronix 和 Bitronix 都有很好的文档,Atomikos 也是一个令人印象深刻的产品,文档也很丰富。就我个人而言,我会选择 Bitronix 或 Atomikos。

PS:老实说,如果这对您来说听起来像中文,您也许应该考虑使用单个数据库(如果这是一个选项,那就去做吧!)或者考虑使用真正的 J2EE 容器,如 JBoss 或 GlassFish正如我在之前的回答中所写。无意冒犯,但是所有这些 JTA 的东西都不是微不足道的,如果您不真正理解为什么需要它,那么走 JOTM 路径也不是那么简单。

Can tx:jta-transaction-manager use id as name so that I can pass it as REF to my service layer like below?

The <tx:jta-transaction-manager> exposes the transaction manager as a Bean in the Spring context with the name "transactionManager".

Can tx:jta-transaction-manager only be used with a J2EE container?

Quoting the Chapter 9. Transaction management from the Spring documentation:

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 Transactions
and JOTM are 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.

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 server means a real J2EE container or a non J2EE container (like Tomcat) with a standalone transaction manager like Atomikos, JOTM, Bitronix, SimpleJTA, JBossTS or 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文