1. 配置文件的配置:
<bean id=" txManager " class="org.springframework.jdbc.datasource.DataSourceTransactionManager> <!--将 dataSource对象注入到 spring的事务管理类中 --> <property name="dataSource" ref=" dataSource" /> </bean> <! 采用 @Transactional注解方式使用事务 (必须加入 tx名字空间 ) --> < tx : annotation-driven transaction-manager=" txManager "/> |
2. 在Service类的注解 :
配置好后就可以在程序中使用 @Transactional来申明事务 @Service @Transactional public class PersonServiceBean implements PersonService { } @Transactional也可以只运行在方法上
|