Spring AOP与事务配置总结
2008-07-24 12:01
155 查看
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
阅读更多相关文章推荐
- applicationContext-common.xml 之spring tx:advice 和 aop:config 配置事务属性详解
- 基于xml配置的Spring AOP切面的几点总结,以及简单的例子
- spring context.xmL配置数据库事务以及aop
- Spring 配置 ——事务:aop:config切入
- Spring AOP中事务配置中七种方式详解
- spring aop方式配置事务中的三个概念 pointcut advice advisor
- spring配置aop的总结
- spring tx:advice 和 aop:config 配置事务
- Spring的自动扫描、数据源配置、AOP和事务等配置
- Spring 2.0 AOP 与事务配置突破
- spring学习笔记(23)基于tx/aop配置切面增强事务
- applicationContext-common.xml 之spring tx:advice 和 aop:config 配置事务属性详解
- spring AOP 拦截器方式配置事务失效
- 在Spring中采用声明式方法对Hibernate和JDBC进行统一的事务配置(AOP)
- spring 事务管理配置总结
- spring采用aop配置事务管理的样例
- 在Spring中采用声明式方法对Hibernate和JDBC进行统一的事务配置(AOP)
- spring配置文件application.xml中的事务总结
- Spring之AOP声明式事务管理(采用xml的配置方式更好)
- spring tx:advice 和 aop:config 配置事务