Spring的声明式事物管理器
<!-- 配置数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://127.0.0.1:3306/webservice"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> </bean>
<!-- 配置事物管理 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean>
<!-- 2.配置事物的通知 --> <tx:advice id="txadvice" transaction-manager="txManager"> <tx:attributes> <!-- 配置哪些方法使用什么样的事物,配置事物的传播特性 --> <tx:method name="add" propagation="REQUIRED" /> <tx:method name="update" propagation="REQUIRED" /> <tx:method name="delete" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="insert" propagation="REQUIRED" /> <tx:method name="get" read-only="true" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice>
<!-- 3.配置事物的切面 --> <aop:config> <aop:pointcut expression="execution(* cn.xst.dao.impl.*.*(..))" id="pointcut" /> <aop:advisor advice-ref="txadvice" pointcut-ref="pointcut" /> </aop:config>