事务管理主要针对数据源进行操作:在数据库方面,通过 TransactionManager 事务管理器进行管理,表明一旦出现错误,该数据源的所有数据全部复原。那么数据库如何判断是否发生了错误呢?这就需要在代码方面,通过 @Transactional 注解管理相应的方法,表示一旦该方法出现错误,那么由该方法调用的数据就要执行回滚。
一、spring-config.xml 文件配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
htt