spring1的声明式事务配置:
<!-- 事务的处理 -->
<!-- Hibernate使用的事物管理器-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="jdbcTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="jdbcDataSource"></property>
</bean>
<!-- 事务处理代理的抽象类,可被继承使用-->
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="confirm*">PROPAGATION_REQUIRED, -BetException</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="set*">PROPAGATION_REQUIRED</prop>
<prop key="do*">PROPAGATION_REQUIRED, -SettleException</prop>
<prop key="settle">PROPAGATION_REQUIRED, -Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="jdbcTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="jdbcTransactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="refuseGaming">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
因为我们的事务一般都放在service层,ok 看下service是如何与上面的事务配置联系起来的
<bean id="matchService" parent="baseTransactionProxy">
<property name="target">
<bean class="com.airinbox.gamester.service.impl.MatchService">
<property name="matchDao">
<ref bean="matchHibernateDao" />
</property>
<property name="gamblingDao">
<ref bean="gamblingHibernateDao" />
</property>
<property name="teamDao">
<ref bean="teamHibernateDao" />
</property>
<property name="starDao">
<ref bean="starHibernateDao" />
</property>
</bean>
</property>
</bean>
ok,spring1.x事务配置完成,下面看spring2的配置简单了很多
<!--Hibernate TransactionManager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 以AspectJ方式 定义 AOP -->
<aop:config >
<!-- 注意,请把第2个*号换为项目package 这里的写法可以参考spring手册 -->
<aop:advisor pointcut="execution(* *..service.*Manager.*(..))" advice-ref="txAdvice"/>
<aop:advisor pointcut="execution(* org.springside.core.dao.*Dao.*(..))" advice-ref="txAdvice"/>
</aop:config>
<!-- 基本事务定义,使用transactionManager作事务管理,默认get*方法的事务为readonly,其余方法按默认设置.
默认的设置请参考Spring文档事务一章. -->
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
是不是简单了很多!
分享到:
相关推荐
<?xml version="1.0" encoding="UTF-8"?><beansxmlns=...
事务声明在Dao中,但是通常都会在Service中来处理多个业务逻辑的关系,如:删除,更新等,此时如果在执行了一个步骤之后抛出抛出异常就会导致数据部完整,所以事务不应该在Dao中处理,而应该在Service...声明式的事务。
Spring声明式事务配置模板2.x;提供通用的配置,系统对一些朋友有用。
Spring声明式事务配置管理方法
Spring_Hibernate使用TransactionInterceptor声明式事务配置.doc
spring3,hibernate4 配置声明式事务管理(annotation方式)
在Spring3中配置声明式事务比早期版本显得更加简便。只需要几行配置文件+注解就可以实现面向切面的AOP事务
spring声明式事务的配置 3. spring2.0配置事务 a) 将spring 1.2升级到spring2.0 i. 去掉spring1.2相关的包 ii. 添加spring2.0的jar包:spring.jar,aspecjrt.jar,aspectjweaver.jar 和cglib-nodep-2.1.3,jar iii. ...
9.6 使用注解配置声明式事务 9.6.1 使用@Transactional注解 9.6.2 通过AspectJ LTW引入事务切面 9.7 集成特定的应用服务器 9.7.1 BEA WebLogic 9.7.2 BEA WebLogic 9.8 小结 第10章 Spring的事务管理难点剖析 10.1 ...
1. 基于Aspectj实现动态数据源...6. 实现事务内切换数据源(支持原生Spring声明式事务哟,仅此一家),并支持多数据源事务回滚(有了它除了跨服务的事务你需要考虑分布式事务,其他都不需要,极大的减少了系统的复杂程度)
Spring源代码解析(六):Spring声明式事务处理.doc
spring声明式事务配置方法.docx
spring声明式事务实例 可复制修改使用。。。。。。。。。。
1.掌握Myeclipse的使用。 2.掌握spring框架和hibernate框架的使用。 3. 掌握整合spring和hibernate的持久化操作编程 4.掌握基于AOP的声明式事务编程...3.配置WEB-INF/applicationContext.xml提供基于AOP的声明式事务
spring+mybatis的声明式事务
Spring 声明式事务和Spring 编程式事务
spring声明式事务处理demo。myeclipse工程
9.6 使用注解配置声明式事务 9.6.1 使用@Transactional注解 9.6.2 通过AspectJ LTW引入事务切面 9.7 集成特定的应用服务器 9.7.1 BEA WebLogic 9.7.2 BEA WebLogic 9.8 小结 第10章 Spring的事务管理难点剖析 10.1 ...
Spring使用TransactionProxyFactoryBean声明式事务配置实例