`

Spring对事务的支持

阅读更多
1. 事务简介

满足以下四个条件:
第一:原子性;
第二:一致性;
第三:隔离性;
第四:持久性;


2. 编程式事务管理

这种方式对业务有侵入,不推荐

Spring提供的事务模版类:
org.springframework.transaction.support.TransactionTemplate

Spring提供的事务管理器:
org.springframework.jdbc.datasource.DataSourceTransactionManager

新建项目Spring405


新建表

create table t_count(
    id int(11) not null primary key auto_increment,
    userId int(11),
    userName varchar(20),
    count int(11)
)
insert into t_count values(1, 1, '张三', 500);
insert into t_count values(2, 2, '李四', 1000);

BankDao.java

package com.andrew.dao;
public interface BankDao {
    public void inMoney(int money, int userId);
    public void outMoney(int money, int userId);
}

BankDaoImpl.java

t_count可以更改操作,修改数据
t_count2运行报错,数据回滚

package com.andrew.dao.impl;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import com.andrew.dao.BankDao;
public class BankDaoImpl implements BankDao {
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    public void setNamedParameterJdbcTemplate(
            NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
    }
    @Override
    public void inMoney(int money, int userId) {
        String sql = "update t_count set count=count+:money where userId=:userId";
        // String sql = "update t_count2 set count=count+:money where userId=:userId";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("money", money);
        sps.addValue("userId", userId);
        namedParameterJdbcTemplate.update(sql, sps);
    }
    @Override
    public void outMoney(int money, int userId) {
        String sql = "update t_count set count=count-:money where userId=:userId";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("money", money);
        sps.addValue("userId", userId);
        namedParameterJdbcTemplate.update(sql, sps);
    }
}

BankService.java

package com.andrew.service;
public interface BankService {
    public void transferAccounts(int count, int userIdA, int userIdB);
}

BankServiceImpl.java

package com.andrew.service.impl;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import com.andrew.dao.BankDao;
import com.andrew.service.BankService;
public class BankServiceImpl implements BankService {
    private BankDao bankDao;
    private TransactionTemplate transactionTemplate;
    public void setBankDao(BankDao bankDao) {
        this.bankDao = bankDao;
    }
    public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
        this.transactionTemplate = transactionTemplate;
    }
    @Override
    public void transferAccounts(final int count, final int userIdA, final int userIdB) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus arg0) {
                bankDao.outMoney(count, userIdA);
                bankDao.inMoney(count, userIdB);
            }
        });
    }
}

jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring4
jdbc.username=root
jdbc.password=root

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <!-- jdbc事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
        <property name="transactionManager" ref="transactionManager"></property>
    </bean>
    <context:property-placeholder location="jdbc.properties"/>
    <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="dataSource"></constructor-arg>
    </bean>
    <bean id="bankDao" class="com.andrew.dao.impl.BankDaoImpl">
        <property name="namedParameterJdbcTemplate" ref="namedParameterJdbcTemplate"></property>
    </bean> 
    <bean id="bankService" class="com.andrew.service.impl.BankServiceImpl">
        <property name="bankDao" ref="bankDao"></property>
        <property name="transactionTemplate" ref="transactionTemplate"></property>
    </bean> 
</beans>

JunitTest.java

package com.andrew.test;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.andrew.service.BankService;
public class JunitTest {
    private ApplicationContext ac;
    @Before
    public void setUp() throws Exception {
        ac = new ClassPathXmlApplicationContext("beans.xml");
    }
    @Test
    public void transferAccounts() {
        BankService bankService = (BankService) ac.getBean("bankService");
        bankService.transferAccounts(50, 1, 2);
    }
}


3. 声明式事务管理

3.1) 使用XML配置声明式事务

新建项目Spring405-02

引入事务的声明
xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd

BankDao.java

package com.andrew.dao;
public interface BankDao {
    public void inMoney(int money, int userId);
    public void outMoney(int money, int userId);
}

BankDaoImpl.java

package com.andrew.dao.impl;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import com.andrew.dao.BankDao;
public class BankDaoImpl implements BankDao {
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    public void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
    }
    @Override
    public void inMoney(int money, int userId) {
        String sql = "update t_count2 set count=count+:money where userId=:userId";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("money", money);
        sps.addValue("userId", userId);
        namedParameterJdbcTemplate.update(sql, sps);
    }
    @Override
    public void outMoney(int money, int userId) {
        String sql = "update t_count set count=count-:money where userId=:userId";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("money", money);
        sps.addValue("userId", userId);
        namedParameterJdbcTemplate.update(sql, sps);
    }
}

BankService.java

package com.andrew.service;
public interface BankService {
    public void transferAccounts(int count,int userIdA,int userIdB);
}

BankServiceImpl.java

package com.andrew.service.impl;
import com.andrew.dao.BankDao;
import com.andrew.service.BankService;
public class BankServiceImpl implements BankService {
    private BankDao bankDao;
    public void setBankDao(BankDao bankDao) {
        this.bankDao = bankDao;
    }
    @Override
    public void transferAccounts(int count, int userIdA, int userIdB) {
        bankDao.outMoney(count, userIdA);
        bankDao.inMoney(count, userIdB);
    }
}

jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring4
jdbc.username=root
jdbc.password=root

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
    <!-- jdbc事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!-- 配置事务通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>
    <!-- 配置事务切面 -->
    <aop:config>
        <!-- 配置切点 -->
        <aop:pointcut id="serviceMethod" expression="execution(* com.andrew.service.*.*(..))" />
        <!-- 配置事务通知 -->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
    </aop:config>
    <context:property-placeholder location="jdbc.properties" />
    <bean id="namedParameterJdbcTemplate"
        class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="dataSource"></constructor-arg>
    </bean>
    <bean id="bankDao" class="com.andrew.dao.impl.BankDaoImpl">
        <property name="namedParameterJdbcTemplate" ref="namedParameterJdbcTemplate"></property>
    </bean>
    <bean id="bankService" class="com.andrew.service.impl.BankServiceImpl">
        <property name="bankDao" ref="bankDao"></property>
    </bean>
</beans>


3.2) 使用注解配置声明式事务

新建项目Spring405-03

BankDao.java

package com.andrew.dao;
public interface BankDao {
    public void inMoney(int money, int userId);
    public void outMoney(int money, int userId);
}

BankDaoImpl.java

package com.andrew.dao.impl;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import com.andrew.dao.BankDao;
public class BankDaoImpl implements BankDao {
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    public void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
    }
    @Override
    public void inMoney(int money, int userId) {
        // String sql = "update t_count2 set count=count+:money where userId=:userId";
        String sql = "update t_count set count=count+:money where userId=:userId";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("money", money);
        sps.addValue("userId", userId);
        namedParameterJdbcTemplate.update(sql, sps);
    }
    @Override
    public void outMoney(int money, int userId) {
        String sql = "update t_count set count=count-:money where userId=:userId";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("money", money);
        sps.addValue("userId", userId);
        namedParameterJdbcTemplate.update(sql, sps);
    }
}

BankService.java

package com.andrew.service;
public interface BankService {
    public void transferAccounts(int count,int userIdA,int userIdB);
}

BankServiceImpl.java

增加@Transactional注解

package com.andrew.service.impl;
import org.springframework.transaction.annotation.Transactional;
import com.andrew.dao.BankDao;
import com.andrew.service.BankService;
@Transactional
public class BankServiceImpl implements BankService {
    private BankDao bankDao;
    public void setBankDao(BankDao bankDao) {
        this.bankDao = bankDao;
    }
    @Override
    public void transferAccounts(int count, int userIdA, int userIdB) {
        bankDao.outMoney(count, userIdA);
        bankDao.inMoney(count, userIdB);
    }
}

jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring4
jdbc.username=root
jdbc.password=root

beans.xml

增加<tx:annotation-driven transaction-manager="transactionManager"/>

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
    <!-- jdbc事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:property-placeholder location="jdbc.properties" />
    <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="dataSource"></constructor-arg>
    </bean>
    <bean id="bankDao" class="com.andrew.dao.impl.BankDaoImpl">
        <property name="namedParameterJdbcTemplate" ref="namedParameterJdbcTemplate"></property>
    </bean>
    <bean id="bankService" class="com.andrew.service.impl.BankServiceImpl">
        <property name="bankDao" ref="bankDao"></property>
    </bean>
</beans>


4. 事务传播行为

事务传播行为:Spring中,当一个service方法调用另外一个service方法的时候,因为每个service方法都有事务,这时候就出现了事务的嵌套;由此,就产生了事务传播行为;
在Spring中,通过配置Propagation,来定义事务传播行为;
PROPAGATION_REQUIRED -- 支持当前事务,如果当前没有事务,就新建一个事务。这是最常见的选择。
PROPAGATION_SUPPORTS -- 支持当前事务,如果当前没有事务,就以非事务方式执行。
PROPAGATION_MANDATORY -- 支持当前事务,如果当前没有事务,就抛出异常。
PROPAGATION_REQUIRES_NEW -- 新建事务,如果当前存在事务,把当前事务挂起。
PROPAGATION_NOT_SUPPORTED -- 以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。
PROPAGATION_NEVER -- 以非事务方式执行,如果当前存在事务,则抛出异常。
<tx:attributes>
    <tx:method name="insert*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="edit*" propagation="REQUIRED" />
    <tx:method name="save*" propagation="REQUIRED" />
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="new*" propagation="REQUIRED" />
    <tx:method name="set*" propagation="REQUIRED" />
    <tx:method name="remove*" propagation="REQUIRED" />
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="change*" propagation="REQUIRED" />
    <tx:method name="get*" propagation="REQUIRED" read-only="true" />
    <tx:method name="find*" propagation="REQUIRED" read-only="true" />
    <tx:method name="load*" propagation="REQUIRED" read-only="true" />
    <tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>


beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
    <!-- jdbc事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!-- 配置事务通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="edit*" propagation="REQUIRED" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="new*" propagation="REQUIRED" />
            <tx:method name="set*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="change*" propagation="REQUIRED" />
            <tx:method name="get*" propagation="REQUIRED" read-only="true" />
            <tx:method name="find*" propagation="REQUIRED" read-only="true" />
            <tx:method name="load*" propagation="REQUIRED" read-only="true" />
            <tx:method name="*" propagation="REQUIRED" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <!-- 配置事务切面 -->
    <aop:config>
        <!-- 配置切点 -->
        <aop:pointcut id="serviceMethod" expression="execution(* com.andrew.service.*.*(..))" />
        <!-- 配置事务通知 -->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
    </aop:config>
    <context:property-placeholder location="jdbc.properties" />
    <bean id="namedParameterJdbcTemplate"
        class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="dataSource"></constructor-arg>
    </bean>
    <bean id="bankDao" class="com.andrew.dao.impl.BankDaoImpl">
        <property name="namedParameterJdbcTemplate" ref="namedParameterJdbcTemplate"></property>
    </bean>
    <bean id="bankService" class="com.andrew.service.impl.BankServiceImpl">
        <property name="bankDao" ref="bankDao"></property>
    </bean>
</beans>
分享到:
评论

相关推荐

    Spring对事务支持

    这份文档以例子的形式讲诉了Spring对事务支持的知识,希望可以帮助学习的人!

    Spring事务管理Demo

    Spring事务管理的目的是确保数据的一致性和完整性,尤其是在多操作、多资源的环境中。本Demo将深入探讨Spring如何实现事务的管理。 首先,Spring提供了两种主要的事务管理方式:编程式事务管理和声明式事务管理。 ...

    spring事务与数据库操作

    ### Spring事务与数据库操作 #### 一、Spring的声明式事务管理 在现代软件开发中,事务处理是非常关键的一部分,特别是在涉及多个数据操作时。Spring框架提供了强大的事务管理能力,可以方便地集成到应用程序中。...

    实验 spring 声明事务

    在实际应用中,Spring 的声明式事务管理不仅限于JDBC,还支持其他数据访问技术,如Hibernate、MyBatis等。同时,Spring还提供了编程式事务管理,允许开发者在代码中手动管理事务,但这种方式通常在更复杂的场景或...

    Spring事务流程图

    Spring事务管理是Spring框架的核心特性之一,主要用于处理应用程序中的数据一致性问题。在Spring中,事务管理分为编程式和声明式两种方式。本篇文章将详细解释Spring事务管理的流程,以及如何通过时序图来理解这一...

    Spring Hibernate事务实例

    例如,所有以"save"、"update"或"delete"开头的方法都要求必须在事务内执行,而其他方法默认支持事务,但不强制。 接下来,我们还需要创建一个Service层接口及其实现类,其中包含需要进行事务管理的业务逻辑。在...

    Spring分布式事务实现

    `xapool.jar`是XAPool,它是Apache软件基金会的一个项目,提供了一个高效的JDBC连接池,对JOTM这样的事务管理器非常有用。 `spring.jar`包含了Spring框架的核心类,其中包括了Spring的事务管理组件。`aspectjweaver...

    深入理解spring的事务管理机制

    **Spring事务的本质**实际上是依赖于底层数据库提供的事务支持。如果没有数据库层面的支持,Spring无法单独实现事务的功能。在传统的JDBC操作中,如果想要利用事务,通常需要手动控制事务的开启、提交或回滚等过程。...

    Spring事务与Java事务比较

    Spring AOP 支持基于接口的代理(JDK 动态代理)和基于类的代理(CGLIB),可以透明地对目标对象进行增强。 总结来说,Spring 框架的事务管理与 Java 原生的事务管理相比,具有更高的抽象层次和更好的可配置性,...

    spring hibernate 事务管理学习笔记(一)

    在实际开发中,理解这部分源码有助于我们更深入地掌握Spring事务管理的工作原理。 至于工具,开发者可以使用诸如IntelliJ IDEA这样的IDE,其中集成的调试工具可以帮助我们跟踪代码执行流程,查看事务状态的变化,...

    Spring2.5实现事务管理(本地事务、分布式事务).doc

    Spring 框架提供了对事务管理的支持,它可以使得事务的管理变得更加简洁和灵活。事务管理是指在多个操作中维持一致性的机制,它可以确保在多个操作中,如果某个操作失败,则整个事务回滚,保证数据的一致性。 在 ...

    spring 事务基于注解模式

    Spring事务管理分为编程式和声明式两种。编程式事务管理通过编程的方式(如使用`TransactionTemplate`或直接调用`PlatformTransactionManager`)来控制事务的开始、提交、回滚等操作。而声明式事务管理则是在配置...

    Spring事务小demo

    通过这个小型的Spring+Mybatis+MySQL项目,你可以动手实践,了解如何配置和使用Spring事务,同时加深对AOP、数据库事务和框架集成的理解。记得在实际应用中根据需求调整事务策略,以确保数据的一致性和完整性。

    Spring事务原理、Spring事务配置的五种方式

    Spring事务原理和配置 Spring事务原理是指Spring框架中的一种机制,用于管理事务,并提供了多种配置方式。事务是指一系列的操作,作为一个整体执行,如果其中某个操作失败,整个事务将回滚。Spring事务原理围绕着两...

    Spring事务管理开发必备jar包

    本资源包提供了进行Spring事务管理开发所需的所有关键库,包括框架基础、核心组件、AOP(面向切面编程)支持、日志处理、编译工具以及与数据库交互的相关jar包。下面将对这些知识点进行详细解释: 1. **Spring框架*...

    Spring事务管理的jar包

    `spring-tx-3.2.0.RELEASE.jar`是Spring事务管理模块的核心库,它包含了Spring对事务管理的所有支持。这个版本的Spring事务管理支持JDBC、Hibernate、JPA、iBatis等多种数据访问技术,可以无缝集成到各种持久层框架...

    spring3.0两种事务管理配置

    * PROPAGATION_NOT_SUPPORTED:不支持事务 * PROPAGATION_NEVER:不允许存在事务 Spring 3.0 的事务管理配置提供了两种方法:基于 XML 的事务管理和基于 @Transactional 的事务管理,这两种方法都可以实现事务管理...

    spring-tx事务管理实例

    总的来说,Spring事务管理通过其强大的声明式事务处理能力和对各种事务策略的支持,使得开发者能够轻松地在应用程序中实现高效、一致的事务处理。通过理解并合理运用上述知识点,开发者可以构建出稳定、健壮的分布式...

    Spring事务类型祥解

    开发者只需在方法上添加`@Transactional`注解,声明该方法需要事务支持,而无需关心事务的具体实现。声明式事务管理更加简洁,易于维护,且能与Spring的其他功能很好地集成。 - `@Transactional`注解的属性: - `...

Global site tag (gtag.js) - Google Analytics