
注解实现实现事务管理很简单,和配置式差不多,配置文件的头文件也要加相应的支持。配置数据源,并开启事务管理支持即可。
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <tx:annotation-driven transaction-manager="transactionManager" />
在需要事务管理的方法上加上spring注解即可
@Transactional(isolation=Isolation.REPEATABLE_READ,propagation=Propagation.REQUIRED,readOnly=false)
public Integer insertUser(UserInfo info) {
Integer index = UserMapper.InsertUser(info);
int x = 1/0;
index = UserMapper.InsertUser(info)+index;
return index;
}
实现效果