Spring事务处理的两种方式 .
来源:互联网 发布:实际多线程编程 编辑:程序博客网 时间:2024/06/05 09:30
spring事务管理:
可以通过两种方式实现:
一是用AOP来控制事务:
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 配置事务特性 -->
<tx:advice id="txAdvice" 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" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory" />
</property>
</bean>
<!-- 配置事务管理 -->
<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="myTransactionManager" />
</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" class="com.test.spring.UserServiceImpl">
<property name="userDAOIF">
<ref local="userDAO" />
</property>
</bean>
<!-- DAO object: Hibernate implementation -->
<bean id="userDAO" class="com.test.hibernate.UserDAOImpl">
<property name="sessionFactory">
<ref local="mySessionFactory" />
</property>
</bean>
- Spring事务处理的两种方式
- Spring事务处理的两种方式
- Spring事务处理的两种方式
- Spring事务处理的两种方式 .
- 事务处理的两种方式的原理
- EJB中事务处理的两种方式
- spring事务处理的几种方式
- spring配置事务处理的五种方式
- Spring中的几种事务处理方式
- Spring有几种事务处理方式
- Spring两种注入方式的对比
- Spring 整合 Struts 的两种方式
- spring整合hibernate的两种方式
- Spring定时器的两种实现方式
- Spring定时器的两种实现方式
- Spring定时器的两种实现方式
- Spring事务管理的两种方式
- spring定时器的两种实现方式
- Android动画开发——Animation动画效果
- 使用 Spring 2.5 注释驱动的 IoC 功能 .
- Mvc利用淘宝Kissy uploader实现图片批量上传附带瀑布流的照片墙
- 设计包含min函数的栈
- 函数调用约定
- Spring事务处理的两种方式 .
- 下载yahoo股票历史数据
- 热爱Spring的五个理由 .
- Unity 到处Assetbundle的脚本
- jQuery Mobile里xxx怎么用呀? (事件篇)
- Android fill_parent和wrap_content分析
- hdu 4651 Partition 整数划分+公式
- android使用代码布局LInearLayout达不到xml的效果(自问自答)
- 使用flashvars将参数通过网页传递给Flash