Spring中的声明式事务的几种配置方式
Spring中的声明式事务的几种配置方式
??????
??????
??????
??????
??????lazy-init="true"?abstract="true">
??????<!--?配置事务管理器?-->
??????<property?name="transactionManager">
???????<ref?bean="transactionManager"?/>
??????</property>
??????<!--?配置事务属性?-->
??????<property?name="transactionAttributes">
???????<props>
????????<prop?key="delete*">PROPAGATION_REQUIRED</prop>
????????<prop?key="add*">PROPAGATION_REQUIRED</prop>
????????<prop?key="update*">PROPAGATION_REQUIRED</prop>
????????<prop?key="save*">PROPAGATION_REQUIRED</prop>
????????<prop?key="find*">PROPAGATION_REQUIRED,readOnly</prop>
???????</props>
??????</property>
?????</bean>
????而具体的模块可以简单的这样配置。只要指明它的parent(父类)就可以了。父类一般把abstract="true",因为在容器加载的时候不需要初始化,等到用的时候再有它的子类调用的时候,再去初始化。
????<bean?id="fundServiceDAOProxy"?parent="transactionBase"?>
??????<property?name="target">
??????<ref?bean="fundService"?/>
??????</property>
?????</bean>
????这样配置的话,如果有多个像fundService这样模块时,可以少些很多重复的代码。
?????第三种:配置声明式事务的方法如下。主要利用BeanNameAutoProxyCreator自动创建事务代理
??????<bean?id="transactionInterceptor"
??????
??????
??????
??????
??????
??????class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
??????<property?name="advice">
??????<ref?bean="transactionInterceptor"?/>
??????</property>
??????<property?name="pattern">
??????<value>.*</value>
??????</property>
??????</bean>
??????这个方法可以针对具体的模块进行拦截并进行事务处理。在你的实际项目中,你可以根据你的情况选用不同的方法。?