Spring中开启事务的第三种:注解配置
步骤
导包
spring-aop-4.3.8.RELEASE.jar
spring-aspects-4.3.8.RELEASE.jar
联盟包:com.springsource.org.aopalliance-1.0.0.jar
织入包:com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
spring-jdbc-4.3.8.RELEASE.jar
spring-tx-4.3.8.RELEASE.jar
导入tx约束
spring-tx-4.3.xsd
xmlns:tx=”http://www.springframework.org/schema/tx”
在配置文件中开启对事务注解的支持
<!-- 开启spring对事务的注解支持 -->
<tx:annotation-driven/>
在方法或者类上添加注解
//可以在类,属性,方法上都可以添加注解,小范围覆盖大范围的
@Transactional(isolation=Isolation.REPEATABLE_READ,propagation=Propagation.REQUIRED,readOnly=true)
public class AccountServiceImpl implements IAccountService{
......
}
service类
//可以在类,属性,方法上都可以添加注解,小范围覆盖大范围的
@Transactional(isolation=Isolation.REPEATABLE_READ,propagation=Propagation.REQUIRED,readOnly=true)
public class AccountServi