gpt4 book ai didi

java - Spring jta 事务管理器

转载 作者:搜寻专家 更新时间:2023-11-01 04:03:47 29 4
gpt4 key购买 nike

使用 Spring :

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

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

对于问题2

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

最佳答案

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

<tx:jta-transaction-manager>将事务管理器公开为 Spring 上下文中名称为“transactionManager”的 Bean。

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

引用Chapter 9. Transaction management来自 Spring 文档:

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.

因此,如第三段中所述,如果您想使用多个事务资源,则需要涉及支持 JTA 的应用程序服务器的全局事务。 支持 JTA 的应用程序服务器 是指真正的 J2EE 容器或非 J2EE 容器(如 Tomcat),带有独立的事务管理器,如 Atomikos , JOTM , Bitronix , SimpleJTA , JBossTSGeronimoTM/Jencks .

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

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

关于java - Spring jta 事务管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1963612/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com