Spring事务管理—aop:pointcut expression解析
2014-11-04 22:29
183 查看
先来看看这个spring的配置文件的配置:
<!--事务管理器-->
<beanid="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"/>
</bean>
<!--配置事务的传播特性-->
<tx:adviceid="txAdvice"transaction-manager="transactionManager">
<tx:attributes>
<tx:methodname="get*"propagation="REQUIRED"read-only="true"/>
<tx:methodname="del*"propagation="REQUIRED"/>
<tx:methodname="save*"propagation="REQUIRED"/>
<tx:methodname="update*"propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--配置事务拦截器拦截哪些类的哪些方法,一般设置成拦截Service-->
<aop:config>
<aop:pointcutexpression="execution(*com.xy.service.*.*(..))"
id="allDaoMethod"/>
<aop:advisoradvice-ref="txAdvice"pointcut-ref="allDaoMethod"/>
</aop:config>
表示com.xy.service包下的所有方法为为事务管理。
execution(*com.aptech.jb.epet.dao.hibimpl.*.*(..))
这样写应该就可以了这是com.aptech.jb.epet.dao.hibimpl包下所有的类的所有方法。。
第一个*代表所有的返回值类型
第二个*代表所有的类
第三个*代表类所有方法最后一个..代表所有的参数。
下面给出一些常见切入点表达式的例子:
任意公共方法的执行:
任何一个以“set”开始的方法的执行:
定义在service包里的任意方法的执行:
定义在service包或者子包里的任意类的任意方法的执行:
<!--事务管理器-->
<beanid="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"/>
</bean>
<!--配置事务的传播特性-->
<tx:adviceid="txAdvice"transaction-manager="transactionManager">
<tx:attributes>
<tx:methodname="get*"propagation="REQUIRED"read-only="true"/>
<tx:methodname="del*"propagation="REQUIRED"/>
<tx:methodname="save*"propagation="REQUIRED"/>
<tx:methodname="update*"propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--配置事务拦截器拦截哪些类的哪些方法,一般设置成拦截Service-->
<aop:config>
<aop:pointcutexpression="execution(*com.xy.service.*.*(..))"
id="allDaoMethod"/>
<aop:advisoradvice-ref="txAdvice"pointcut-ref="allDaoMethod"/>
</aop:config>
表示com.xy.service包下的所有方法为为事务管理。
execution(*com.aptech.jb.epet.dao.hibimpl.*.*(..))
这样写应该就可以了这是com.aptech.jb.epet.dao.hibimpl包下所有的类的所有方法。。
第一个*代表所有的返回值类型
第二个*代表所有的类
第三个*代表类所有方法最后一个..代表所有的参数。
下面给出一些常见切入点表达式的例子:
任意公共方法的执行:
execution(public**(..))
任何一个以“set”开始的方法的执行:
execution(*set*(..))
AccountService接口的任意方法的执行:
execution(*com.xyz.service.AccountService.*(..))
定义在service包里的任意方法的执行:
execution(*com.xyz.service.*.*(..))
定义在service包或者子包里的任意类的任意方法的执行:
execution(*com.xyz.service..*.*(..))
相关文章推荐
- Spring事务管理—aop:pointcut expression解析(转)
- Spring事务管理—AOP/Annotation
- Spring事务管理——AOP注解事务管理
- spring事务管理的AOP实现原理
- Spring事务管理(2)-AOP注册解析器
- Spring事务管理—aop:pointcut expression 常见切入点表达式及事物说明
- spring事务管理,AOP模式
- spring事务管理AOP (mini show)
- Spring事务管理(4)-AOP创建代理
- Spring事务管理之AOP方法
- Spring事务管理—aop:pointcut expression解析
- Spring事务管理—aop:pointcut 属性expression格式说明
- Spring事务管理—aop:pointcut expression解析
- Spring事务管理-aop切入配置
- Spring事务管理、Aop
- Spring事务管理—aop:pointcut expression解析
- Spring事务管理—aop:pointcut expression解析
- Spring事务管理—aop:pointcut expression解析
- Spring事务管理—aop:pointcut expression解析