一.注解方式创建事务
1.配置文件
(1)创建事务管理器
<bean id="TransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
</bean> 
(2)开启事务注解
 <tx:annotation-driven transaction-manager="TransactionManager"></tx:annotation-driven> 
(3)在要添加事务的方法或者类上加上@Transactional,若加在类上,则类所有的方法都添加事务。
该注解中有一些参数
①propagation事务的传播行为

②ioslation事务的隔离性
与之前mysql事务的隔离性类似
③timeout超时时间
事务在设置时间内要提交,不然回滚(默认值为-1)
④readOnly是否只读
默认值为false,可以增删改查,设置成true后只能查询。
⑤rollbackFor回滚
设置哪些异常要回滚
⑤noRollbackFor不回滚
设置哪些异常不要回滚
二.xml配置创建事务
与注解方式相比,没有开启事务注解和@Transactional。
再加上
1.配置通知
 <tx:advice id="名字">
        <tx:attributes>
            <tx:method name="要加事务的方法名"/>//还可以加入注解中参数有的属性
        </tx:attributes>
    </tx:advice> 
2.配置切入点
<aop:config>
        <aop:pointcut id="pt" expression="execution表达式"/>
        <aop:advisor advice-ref="名字" pointcut-ref="pt"></aop:advisor>
    </aop:config>









