Spring事务处理的两种方式
来源:互联网 发布:mac系统快速回到桌面 编辑:程序博客网 时间:2024/06/05 01:57
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定时器的两种实现方式
- jsp乱码的解决之道
- 判断回文整理
- 1.7 Native代码产生器: NGen.exe
- A Unix Utility You Should Know About: Pipe Viewer
- SSH配置中Spring对Hib的自动事务处理
- Spring事务处理的两种方式
- I come back!
- Tomcat及MySQL服务配置
- 如何在 Journal Template 中得到当前登录用户
- grub进入windows和linux
- JQuery-Truncate插件(更多,截字)
- 学校的潜规则
- 电子锁图
- 【Sos】我想编个小小的手机应用软件