Spring 1.0的标准事务配置
<bean id="baseTxService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="proxyTargetClass" value="true"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
</props>
</property>
<property name="preInterceptors">
<list>
<ref bean="methodSecurityInterceptor"/>
</list>
</property>
</bean> <bean id="bookManager" parent="baseTxService">
<property name="target">
<bean class="org.springside.bookstore.admin.manager.BookManager"/>
</property>
</bean>
Spring 2.0的新配置:
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.xyz.service..*Manager.*(..))" advice-ref="txAdvice"/>
<aop:advisor pointcut="execution(* com.xyz.service..*Manager.save(..))" advice-ref="fooAdvice"/>
</aop:config><tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<bean id="bookManager" class="org.springside.bookstore.commons.service.BookManager"/>
execution(* *..BookManager.save(..))的解读:
- 第一颗* 代表ret-type-pattern 返回值可任意,
- *..BookManager 代表任意Pacakge里的BookManager类。
如果写成com.xyz.service.* 则代表com.xyz.service下的任意类
com.xyz.service..* com.xyz.service则代表com.xyz.service及其子package下的任意类 - save代表save方法,也可以写save* 代表saveBook()等方法
- (..) 匹配0个参数或者多个参数的,任意类型
(x,..) 第一个参数的类型必须是X
(x,, ,s,..) 匹配至少4个参数,第一个参数必须是x类型,第二个和第三个参数可以任意,第四个必须是s类型。
详情请见http://wiki.springside.org.cn/display/springside/Spring+Aop
本文介绍了Spring框架1.0和2.0版本中事务管理的不同配置方式,包括使用TransactionProxyFactoryBean和AOP配置,并解释了execution表达式的含义。
168万+

被折叠的 条评论
为什么被折叠?



