spring的事务配置方法

  spring事务的配置有两种方式

1.xml配置的声明式事务配置

(1)配置数据源信息dataSource(使用阿里的数据源)

<bean />
</bean>

(2)注册事务管理器(使用的是DataSourceTransactionManager事务管理器)

<bean >

(3)通过代理方式配置事务通知,配置事务的切入点,将切入点作用到目标对象中(组装切面)

   (3.1)配置事务通知

<tx:advice />
</tx:attributes>
</tx:advice>

(3.2)组装切点表达式

<!-- 组装切面 -->
<aop:config>
<!-- 配置切点表达式 ,对service包下面的所有方法都启用事务-->
<aop:pointcut expression="execution(* nyist.e3.service..*.*(..))"
/>
</aop:config>

2.基于注解方式的事务配置

只需要在spring中开启事务配置的注解即可

<!-- 开启事务注解 -->
<mvc:annotation-driven />