1.添加需要依赖的jar
(1)spring-tx
2.在配置文件中引入事务使用的命名空间,xsd文件引入
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/tx"
3.配置事务管理者
<!--spring框架提供了事务的管理操作-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="datasource"/>
</bean>
4.开启声明式事务
<tx:annotation-driven transaction-manager="transactionManager"/>
5.在业务逻辑层添加事务的管理(对应的方法上添加注解)
@Transactional
6.注意:添加事务管理的方法不能处理异常