Spring 事务机制
文章转自:http://blog.csdn.net/lenolong/article/details/3945618
spring事务管理:
可以通过两种方式实现,一是用AOP来控制事务:
<!-- 配置事务管理器 -->
<bean id="transactionManager" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
<!--
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="deploy*" propagation="REQUIRED"/>
<tx:method name="submit*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
-->
</tx:attributes>
</tx:advice>
<!-- 配置哪些类的方法进行事务管理 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution (* com.bjsxt.oa.managers.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
二是用事务拦截器的方式来控制事务:
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="myTransactionManager" />
</property>
</bean>
<!-- 配置事务管理 -->
<bean id="userService" />
</property>
<property name="target">
<ref local="loginTarget" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- OrderTarget primary business object implementation -->
<bean id="loginTarget" />
</property>
</bean>
<!-- DAO object: Hibernate implementation -->
<bean id="userDAO" />
</property>
</bean>