spring1.x spring2的声明式事务配置
来源:互联网 发布:招商证券炒股软件 编辑:程序博客网 时间:2024/05/22 18:34
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>
是不是简单了很多!
- spring1.x spring2的声明式事务配置
- spring1.x与spring2声明式事务管理的配置
- Spring1.x声明式事务
- 配置Spring2.0声明式事务
- spring2.x的超easy事务配置。。。
- Spring2.x的事务配置策略
- Spring2.X以AspectJ 式AOP 配置事务
- Spring2.x中的声明性事务(使用Annotation)
- 对比Spring1.0 与 2.0 的事务配置方式
- Spring1.0 与 2.0 事务配置方式的对比
- Spring1.x Aop配置方式
- spring2與spring1的單例模式的配置區別
- Spring1.x使用TransactionProxyFactoryBean创建事务代理
- Spring3.x_Struts2.x_Hibernate3.x整合之声明式事务配置
- Spring 的声明式事务配置
- Spring声明式事务的配置方式
- spring2.0 事务配置
- spring2.5+ 配置事务
- Hibernate3 核心API
- C++ GUI Programming with Qt 4
- SQL SERVER 返回自动生成的标识ID
- 查所有表名 select name from syscolumns where id=object_id('ReorgDB.dbo.Reorg_ReorgInfor')
- Class.forName
- spring1.x spring2的声明式事务配置
- 我的Delphi7里程碑(认识Delphi7的基本类型)
- CSS基础
- 快来测试你的脑年龄
- CSS规则层叠时的优先级算法
- 国人眼中的Scrum
- 一个职业顾问的真情告白
- Ruby语言的发展趋势和启示
- HTML基础标记