- 注解配置
a. 注册事务管理器切面到容器中
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
b. 开启基于注解的事务驱动
<tx:annotation-driven transaction-manager=" "></tx:annotation-driven>
c. 在事务方法上标注@Transactional(配置属性值)
- xml配置
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--事务建议,指定事务方法,为每个事务方法配置事务的属性-->
<tx:advice transaction-manager="transactionManager" id="myTX">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!--将事务切面切入到切入点(方法)-->
<aop:config>
<aop:pointcut id="myPointcut" expression="execution(* com.wdc.service.*.*(..))"/>
<aop:advisor advice-ref="myTX" pointcut-ref="myPointcut"></aop:advisor>
</aop:config>