`
simgsg
  • 浏览: 96019 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Spring JTA应用之JOTM配置

 
阅读更多
<p>JOTM(Java Open Transaction Manager)是ObjectWeb的一个开源JTA实现,本身也是开源应用程序服务器JOnAS(Java Open Application Server)的一部分,为其提供JTA分布式事务的功能。Spring对JOTM提供了较好的支持,提供了一个org.springframework.transaction.jta.JotmFactoryBean的支持类,在Spring2.0中也包含了JOTM相关的一些library。    <br>jotm的下载地址为http://jotm.objectweb.org,最新版本为2.0.10.     <br>下载完成后解压缩,然后打开jotm下面conf文件夹,拷贝carol.properties文件到classpath中,并修改这个文件如下     <br>carol.properties </p>  <p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>  <ol>
<li># do not use CAROL JNDI wrapper </li>    <li>carol.start.jndi=false</li>    <li>    </li>
<li># do not start a name server </li>    <li>carol.start.ns=false</li>    <li>    </li>
<li># Naming Factory </li>    <li>carol.jndi.java.naming.factory.url.pkgs=org.apache.naming </li> </ol>
<pre># do not use CAROL JNDI wrapper
carol.start.jndi=false
# do not start a name server
carol.start.ns=false
# Naming Factory
carol.jndi.java.naming.factory.url.pkgs=org.apache.naming</pre>

<br>上面配置文件的目的是不使用JNDI的方式来加载JOTM的配置,当然也可以根据需要选择其它的一些配置,例如JTOM所提供的默认配置。

<br>然后开始在Spring上下文中配置JOTM,在classpath中建立一个ApplicationContext-jotm.xml,配置如下

<br>ApplicationContext-jotm.xml

<p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>

<ol>
<li>&lt;?xml version="1.0" encoding="UTF-8"?&gt; </li>

  <li>&lt;beans xmlns="http://www.springframework.org/schema/beans"</li>

  <li> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</li>

  <li> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt; </li>

  <li>

  </li>
<li> &lt;bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/&gt; </li>

  <li>

  </li>
<li> &lt;bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt; </li>

  <li> &lt;property name="userTransaction" ref="jotm" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="dataSource"&gt; </li>

  <li> &lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="transactionManager" ref="jotm" /&gt; </li>

  <li> &lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt; </li>

  <li> &lt;property name="url" value="jdbc:MySQL://localhost:3306/test" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;property name="user" value="root" /&gt; </li>

  <li> &lt;property name="password" value="admin" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="dataSource"&gt; </li>

  <li> &lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="transactionManager" ref="jotm" /&gt; </li>

  <li> &lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt; </li>

  <li> &lt;property name="url" value="jdbc:MySQL://localhost:3306/test2" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;property name="user" value="root" /&gt; </li>

  <li> &lt;property name="password" value="admin" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="template1" class="org.springframework.jdbc.core.JdbcTemplate"&gt; </li>

  <li> &lt;property name="dataSource" ref="ds1" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="template2" class="org.springframework.jdbc.core.JdbcTemplate"&gt; </li>

  <li> &lt;property name="dataSource" ref="ds2" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="dao1" class="com.xa.dao.UserDao1"&gt; </li>

  <li> &lt;property name="jdbcTemplate"&gt; </li>

  <li> &lt;ref bean="template1"&gt;&lt;/ref&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="dao2" class="com.xa.dao.UserDao2"&gt; </li>

  <li> &lt;property name="jdbcTemplate"&gt; </li>

  <li> &lt;ref bean="template2"&gt;&lt;/ref&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="userServiceTarget" class="com.xa.service.UserServiceImpl"&gt; </li>

  <li> &lt;property name="dao1" ref="dao1"/&gt; </li>

  <li> &lt;property name="dao2" ref="dao2"/&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li>

  </li>
<li> &lt;bean id="userTest" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt; </li>

  <li> &lt;property name="transactionManager"&gt; </li>

  <li> &lt;ref bean="txManager"/&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;property name="target"&gt; </li>

  <li> &lt;ref bean="userServiceTarget"/&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;property name="transactionAttributes"&gt; </li>

  <li> &lt;props&gt; </li>

  <li> &lt;prop key="insert*"&gt;PROPAGATION_REQUIRED,-Exception&lt;/prop&gt; </li>

  <li> &lt;/props&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>&lt;/beans&gt; </li>
</ol>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt;
&lt;bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/&gt;
&lt;bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
&lt;property name="userTransaction" ref="jotm" /&gt;
&lt;/bean&gt;
&lt;bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt;
&lt;property name="dataSource"&gt;
&lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt;
&lt;property name="transactionManager" ref="jotm" /&gt;
&lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt;
&lt;property name="url" value="jdbc:MySQL://localhost:3306/test" /&gt;
&lt;/bean&gt;
&lt;/property&gt;
&lt;property name="user" value="root" /&gt;
&lt;property name="password" value="admin" /&gt;
&lt;/bean&gt;
&lt;bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt;
&lt;property name="dataSource"&gt;
&lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt;
&lt;property name="transactionManager" ref="jotm" /&gt;
&lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt;
&lt;property name="url" value="jdbc:MySQL://localhost:3306/test2" /&gt;
&lt;/bean&gt;
&lt;/property&gt;
&lt;property name="user" value="root" /&gt;
&lt;property name="password" value="admin" /&gt;
&lt;/bean&gt;
&lt;bean id="template1" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
&lt;property name="dataSource" ref="ds1" /&gt;
&lt;/bean&gt;
&lt;bean id="template2" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
&lt;property name="dataSource" ref="ds2" /&gt;
&lt;/bean&gt;
&lt;bean id="dao1" class="com.xa.dao.UserDao1"&gt;
&lt;property name="jdbcTemplate"&gt;
&lt;ref bean="template1"&gt;&lt;/ref&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id="dao2" class="com.xa.dao.UserDao2"&gt;
&lt;property name="jdbcTemplate"&gt;
&lt;ref bean="template2"&gt;&lt;/ref&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id="userServiceTarget" class="com.xa.service.UserServiceImpl"&gt;
&lt;property name="dao1" ref="dao1"/&gt;
&lt;property name="dao2" ref="dao2"/&gt;
&lt;/bean&gt;
&lt;bean id="userTest" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;
&lt;property name="transactionManager"&gt;
&lt;ref bean="txManager"/&gt;
&lt;/property&gt;
&lt;property name="target"&gt;
&lt;ref bean="userServiceTarget"/&gt;
&lt;/property&gt;
&lt;property name="transactionAttributes"&gt;
&lt;props&gt;
&lt;prop key="insert*"&gt;PROPAGATION_REQUIRED,-Exception&lt;/prop&gt;
&lt;/props&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;/beans&gt;</pre>

<br>上面是一个完整的Spring上下文配置,可以看第一个bean “jotm”,实际上引用了Spring内部所提供的对JOTM支持的工厂类,参考下面的配置代码段

<p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>

<ol>
<li>&lt;bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/&gt; </li>
</ol>
<pre>&lt;bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/&gt;</pre>

<br>随后,配置了JTA事务管理器,并且在管理器中使用上面所配置的jotm,如下面的代码

<p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>

<ol>
<li>&lt;bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt; </li>

  <li> &lt;property name="userTransaction" ref="jotm" /&gt; </li>

  <li>&lt;/bean&gt; </li>
</ol>
<pre>&lt;bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
&lt;property name="userTransaction" ref="jotm" /&gt;
&lt;/bean&gt;</pre>

<br>再接下来就是配置多个数据源了,使用jotm提供的org.enhydra.jdbc.pool.StandardXAPoolDataSource类,根据类名可以明确地看出它是用以配置多个数据源的啦,配置的代码如下

<p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>

<ol>
<li>&lt;bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="dataSource"&gt; </li>

  <li> &lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="transactionManager" ref="jotm" /&gt; </li>

  <li> &lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt; </li>

  <li> &lt;property name="url" value="jdbc:MySQL://localhost:3306/test" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;property name="user" value="root" /&gt; </li>

  <li> &lt;property name="password" value="admin" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li>

  </li>
<li> &lt;bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="dataSource"&gt; </li>

  <li> &lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt; </li>

  <li> &lt;property name="transactionManager" ref="jotm" /&gt; </li>

  <li> &lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt; </li>

  <li> &lt;property name="url" value="jdbc:MySQL://localhost:3306/test2" /&gt; </li>

  <li> &lt;/bean&gt; </li>

  <li> &lt;/property&gt; </li>

  <li> &lt;property name="user" value="root" /&gt; </li>

  <li> &lt;property name="password" value="admin" /&gt; </li>

  <li> &lt;/bean&gt; </li>
</ol>
<pre>&lt;bean id="ds1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt;
&lt;property name="dataSource"&gt;
&lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt;
&lt;property name="transactionManager" ref="jotm" /&gt;
&lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt;
&lt;property name="url" value="jdbc:MySQL://localhost:3306/test" /&gt;
&lt;/bean&gt;
&lt;/property&gt;
&lt;property name="user" value="root" /&gt;
&lt;property name="password" value="admin" /&gt;
&lt;/bean&gt;
&lt;bean id="ds2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"&gt;
&lt;property name="dataSource"&gt;
&lt;bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"&gt;
&lt;property name="transactionManager" ref="jotm" /&gt;
&lt;property name="driverName" value="com.mysql.jdbc.Driver" /&gt;
&lt;property name="url" value="jdbc:MySQL://localhost:3306/test2" /&gt;
&lt;/bean&gt;
&lt;/property&gt;
&lt;property name="user" value="root" /&gt;
&lt;property name="password" value="admin" /&gt;
&lt;/bean&gt;</pre>

<br>这里配置的两个数据源都连接到本地的mysql,实际上可以连接到不同的db server和不同类型的数据库,已经经过测试,这里为了方便,在本地建立了两个不同的数据库(test,test2)做测试。

<br>随后的配置基本上和普通的Spring上下文配置相同了,根据不同的数据源配置两个jdbcTemplate,两个dao分别引用不同的jdbcTemplate, 将两个dao注入到UserService中, 最后将service纳入事务管理,并在事务代理配置中配置回滚规则,意思为如遇异常,则强制回滚内容。配置如下所示

<p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>

<ol>
<li>&lt;property name="transactionAttributes"&gt; </li>

  <li> &lt;props&gt; </li>

  <li> &lt;prop key="insert*"&gt;PROPAGATION_REQUIRED,-Exception&lt;/prop&gt; </li>

  <li> &lt;/props&gt; </li>

  <li>&lt;/property&gt; </li>
</ol>
<pre>&lt;property name="transactionAttributes"&gt;
&lt;props&gt;
&lt;prop key="insert*"&gt;PROPAGATION_REQUIRED,-Exception&lt;/prop&gt;
&lt;/props&gt;
&lt;/property&gt;</pre>

<br>这样,一个使用JOTM JTA事务的简单应用算大致成型了,最后,写一个JUnit,来测试一下结果

<br>TestXa.java

<p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>

<ol>
<li>package com.xa; </li>

  <li>

  </li>
<li>import org.springframework.context.ApplicationContext; </li>

  <li>import org.springframework.test.AbstractDependencyInjectionSpringContextTests; </li>

  <li>

  </li>
<li>import com.xa.service.UserService; </li>

  <li>

  </li>
<li>public class TestXa extends AbstractDependencyInjectionSpringContextTests </li>

  <li>{ </li>

  <li>protected String[] getConfigLocations() { </li>

  <li>return new String[] { "classpath:ApplicationContext-jotm.xml" }; </li>

  <li> } </li>

  <li>

  </li>
<li>public void testInsertBothDatabase() { </li>

  <li> ApplicationContext ctx = this.getApplicationContext(); </li>

  <li> UserService ut = (UserService)ctx.getBean("userTest"); </li>

  <li>try { </li>

  <li> ut.insertBothDatabase("1", null); </li>

  <li> } </li>

  <li>catch (Exception e) { </li>

  <li> e.printStackTrace(); </li>

  <li> } </li>

  <li> } </li>

  <li>} </li>
</ol>
<pre>package com.xa;
import org.springframework.context.ApplicationContext;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import com.xa.service.UserService;
public class TestXa extends AbstractDependencyInjectionSpringContextTests
{
protected String[] getConfigLocations() {
return new String[] { "classpath:ApplicationContext-jotm.xml" };
}
public void testInsertBothDatabase() {
ApplicationContext ctx = this.getApplicationContext();
UserService ut = (UserService)ctx.getBean("userTest");
try {
ut.insertBothDatabase("1", null);
}
catch (Exception e) {
e.printStackTrace();
}
}
}</pre>

<br>在test中,调用了UserService的insertBothDatabase方法,有两个参数,userId和UserName,另外在方法的实现中调用了两个使用不同数据源dao,分别向两个不同的数据库插入输入,而test2数据库的xa_test表中,name字段是不允许为空的,因此,在插入test2数据库时会失败.

<br>运行这个test,然后察看数据库结果:),test和test2数据库中都没有插入成功,看serviceImpl中的代码可以知道,逻辑上dao1会先于dao2执行,但是由于JTA事务,在dao2插入数据出现异常时整个事务被回滚,由于事务被配置在service层,dao1和dao2都被纳入一个事务进行管理,呵呵。修改一下方法的参数,修改为

<p>Java代码 <a href="http://tom-duan.javaeye.com/blog/147594#"></a></p>

<ol>
<li>ut.insertBothDatabase("1", "name1"); </li>
</ol>
<pre>ut.insertBothDatabase("1", "name1");</pre>

<br>然后再试试test看数据库结果,如何?
分享到:
评论

相关推荐

    Java分布式开发spring+jta+jotm

    "Java分布式开发spring+jta+jotm"的主题涵盖了Spring框架在分布式系统中的应用,特别是如何利用JTA和JOTM来处理跨资源的分布式事务。理解和掌握这些技术对于构建可扩展、健壮的Java应用至关重要。通过深入学习和实践...

    spring JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器)

    3. **Spring配置**:在Spring的配置文件中,使用`jee:jta-data-source`或`jee:resource-ref`元素来引用之前创建的JNDI数据源,并配置`PlatformTransactionManager`为`org.objectweb.jotm.CurrentJOTM`。 **Atomikos...

    spring + JTA + JOTM实现分布式事务

    接下来,我们将结合Spring框架来讨论如何配置和使用JTA和JOTM。Spring是一个强大的企业级应用开发框架,它提供了一整套事务管理解决方案,包括编程式和声明式事务管理。对于分布式事务,Spring支持JTA事务管理,并且...

    多数据源 更新 spring jta java jotm

    要在Spring中配置JOTM,首先添加JOTM和Spring的JTA依赖到项目中。然后,定义一个`PlatformTransactionManager` bean,使用`JotmFactoryBean`来创建JOTM实例。这样,Spring就可以利用JOTM管理事务,确保在多数据源...

    Spring+iBatis+JOTM实现JTA事务

    通过这样的配置和测试,我们可以验证Spring+iBatis+JOTM的JTA事务管理功能是否正常工作。这种方式特别适用于需要在非J2EE容器中实现分布式事务的场景,为应用提供了强大的事务管理能力。然而,需要注意的是,JTA事务...

    spring mybatis jta jotm atomikos 配置

    NULL 博文链接:https://onlyor.iteye.com/blog/1483289

    spring-hibernate-jotm 例子

    而“jotm-2.0.10”则是JOTM的具体版本,包含其核心组件和必要的依赖,用于在Spring环境中配置和使用JOTM。 为了运行这个示例,你需要将这些jar包添加到你的项目类路径中,然后配置Spring的事务管理器为JOTM,并配置...

    Spring+Jotm+Hibernate+Oracle+Junit 实现JTA分布式事务要求Demo工程

    2.Spring+Jotm整合实现JTA分布式事务,应用场景如转账等,同一事务内完成db1用户加100元、db2用户减100元。 3.Spring+Junit4单元测试,优点:不会破坏数据库现场,等等。 (特别注意:Spring3.0里不在提供对jotm的...

    spring 3.0.5 + jotm 实现的的spring mvc 的例子

    标题中的“spring 3.0.5 + jotm 实现的的spring mvc 的例子”表明这是一个关于使用Spring 3.0.5版本与JOTM(Java Open Transaction Manager)结合构建Spring MVC应用的示例项目。这个项目可能旨在演示如何在Spring ...

    JOTM配置分布式事务

    &lt;description&gt;springJTA &lt;!-- JOTM 实例引用了 Spring 内部所提供的对 JOTM 支持的工厂类 --&gt; &lt;bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"&gt; &lt;!-- JTA 事务管理器在管理...

    在Spring中使用JTA事务管理

    在Spring框架中,JTA(Java Transaction API)事务管理是一种用于处理分布式事务的高级机制,它允许应用程序在多个数据源之间进行协调的事务操作。本文将详细介绍如何在Spring中使用JTA事务管理,包括通过集成JOTM...

    spring下jotm jta实现小结

    NULL 博文链接:https://liangzhijian.iteye.com/blog/1404534

    spring+jotm+ibatis+mysql实现JTA分布式事务

    首先,Spring框架是Java开发中最常用的应用框架之一,它提供了全面的编程和配置模型,包括对事务管理的支持。在本项目中,Spring被用来协调各个组件,并提供声明式事务管理。Spring支持JTA(Java Transaction API)...

    JTA事务源码示例

    Spring+iBatis+JOTM实现JTA事务: 如何处理跨库事物:spring + jtom 的jta事务是个很好的选择. 这个源码示例非常不错,包括所有的源码和jar包,下载后eclipse 或 myeclipse 导入就能用。 里面有详细的说明和注释,...

    Spring+JOTM 分布式事务管理

    Spring框架作为一个广泛使用的Java应用程序开发框架,提供了多种支持事务管理的解决方案,其中包括集成JOTM(Java Open Transaction Manager)来处理分布式事务。本文将深入探讨Spring与JOTM结合使用的知识点,帮助...

    spring+jotm 多数据源事务管理(二)hibernate

    在Spring框架中,多数据源事务管理是一项关键任务,特别是在大型企业级应用中,往往需要同时操作多个数据库。本篇文章将聚焦于如何结合Spring和JOTM(Java Open Transaction Manager)来实现多数据源的事务管理,...

    spring+jotm 多数据源事务管理(一)jdbc

    在Spring框架中,事务管理是核心功能之一,它允许开发者以声明式或编程式的方式管理应用程序的事务。在处理多数据源的情况下,事务管理尤为重要,因为它确保了数据的一致性和完整性。本文将介绍如何结合Spring和JOTM...

    分布式事务JTA之实践:Spring+ATOMIKOS

    Spring框架作为Java领域广泛使用的轻量级框架,提供了对JTA的支持,使得开发者可以方便地在应用中集成和管理事务。Spring的Transaction API允许我们通过编程或声明式方式控制事务,极大地简化了事务管理的复杂性。 ...

    spring+jotm 多数据源事务管理(三)JNDI+Tomcat

    &lt;bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" /&gt; &lt;!-- 定义事务管理器 --&gt; &lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt;...

Global site tag (gtag.js) - Google Analytics