事务管理一般有编程式和声明式两种,编程式是直接在代码中进行编写事物处理过程,而声名式则是通过注解方式或者是在xml文件中进行配置,相对编程式很方便

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:tx="http://www.springframework.org/schema/tx"
    5. xmlns:aop="http://www.springframework.org/schema/aop"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans
    7. http://www.springframework.org/schema/beans/spring-beans.xsd
    8. http://www.springframework.org/schema/tx
    9. http://www.springframework.org/schema/tx/spring-tx.xsd">

    JDBC事务

    1. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    2. <property name="dataSource" ref="dataSource" />
    3. </bean>
    4. <tx:annotation-driven transaction-manager="transactionManager" />

    Hibernate事务

    1. <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    2. <property name="sessionFactory" ref="sessionFactory" />
    3. </bean>
    4. <tx:annotation-driven transaction-manager="transactionManager" />

    JPA事务

    1. <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    2. <property name="sessionFactory" ref="sessionFactory" />
    3. </bean>
    4. <tx:annotation-driven transaction-manager="transactionManager" />

    Java原生API事务

    1. <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    2. <property name="transactionManagerName" value="java:/TransactionManager" />
    3. </bean>
    4. <tx:annotation-driven transaction-manager="transactionManager" />

    spring所有的事务管理策略类都继承自org.springframework.transaction.PlatformTransactionManager接口
    **