Spring AOP中pointcut expression表达式解析 及匹配多个条件
Spring中事务控制相关配置:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="insert*" rollback-for="Exception"/>
<tx:method name="update*" rollback-for="Exception"/>
<tx:method name="delete*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="dbServiceOperation" expression="execution(* com.htt..*Service.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="dbServiceOperation"/>
</aop:config>
其中的“aop:pointcut”标签中"expression"的写法规则如下:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)
ret-type-pattern,name-pattern(param-pattern)是必须的.
ret-type-pattern:标识方法的返回值,需要使用全路径的类名如java.lang.String,也可以为*表示任何返回值;
name-pattern:指定方法名,*代表所有,例如set*,代表以set开头的所有方法.
param-pattern:指定方法参数(声明的类型),(..)代表所有参数,(*)代表一个参数,(*,String)代表第一个参数为任何值,第二个为String类型.
表达式例子如下:
任意公共方法的执行:
execution(public * *(..))
任何一个以“set”开始的方法的执行:
execution(* set*(..))
AccountService 接口的任意方法的执行:
execution(* com.xyz.service.AccountService.*(..))
定义在service包里的任意方法的执行:
execution(* com.xyz.service.*.*(..))
定义在service包和所有子包里的任意类的任意方法的执行:
execution(* com.xyz.service..*.*(..))
定义在pointcutexp包和所有子包里的JoinPointObjP2类的任意方法的执行:
execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
在多个表达式之间使用 ||,or表示 或,使用 &&,and表示 与,!表示 非.例如:
<aop:config>
<aop:pointcut id="pointcut" expression="(execution(* com.ccboy.dao..*.find*(..))) or (execution(* com.ccboy.dao..*.query*(..)))"/>
<aop:advisor advice-ref="jdbcInterceptor" pointcut-ref="pointcut" />
</aop:config>
Spring AOP中pointcut expression表达式解析 及匹配多个条件的更多相关文章
- 转载《Spring AOP中pointcut expression表达式解析 及匹配多个条件》
原文地址:https://www.cnblogs.com/rainy-shurun/p/5195439.html 原文 Pointcut 是指那些方法需要被执行"AOP",是由&q ...
- Spring AOP中pointcut expression表达式解析
Pointcut 是指那些方法需要被执行"AOP",是由"Pointcut Expression"来描述的. Pointcut可以有下列方式来定义或者通过&am ...
- Spring AOP 中pointcut expression表达式解析及配置
Pointcut是指那些方法需要被执行”AOP”,是由”Pointcut Expression”来描述的. Pointcut可以有下列方式来定义或者通过&& || 和!的方式进行组合. ...
- Spring AOP中 pointcut expression表达式解析
任意公共方法的执行: execution(public * *(..)) 任何一个以“set”开始的方法的执行: execution(* set*(..)) AccountService 接口的任意方 ...
- Spring AOP中pointcut expression表达式
Pointcut 是指那些方法需要被执行"AOP",是由"Pointcut Expression"来描述的. Pointcut可以有下列方式来定义或者通过&am ...
- Spring AOP 中pointcut expression表达式
原文地址——http://blog.csdn.net/qq525099302/article/details/53996344 Pointcut是指那些方法需要被执行”AOP”,是由”Pointcut ...
- spring aop中pointcut表达式完整版
spring aop中pointcut表达式完整版 本文主要介绍spring aop中9种切入点表达式的写法 execute within this target args @target @with ...
- Spring AOP 中@Pointcut的用法
Spring Aop中@pointCut的用法,格式:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? nam ...
- spring AOP pointcut expression表达式解析
Pointcut 是指那些方法需要被执行"AOP",是由"Pointcut Expression"来描述的.Pointcut可以有下列方式来定义或者通过& ...
随机推荐
- Hadoop 基本操作
1.关闭安全模式 hadoop dfsadmin -safemode leave
- ORA-00205
场景 数据库启动时报错.关闭前还是正常运行的,再次启动时,就报了以下错误. Copyright (c) , , Oracle. All rights reserved. Connected to an ...
- Hbase之测试数据
info ship user name age height phone addr email dept salary create 'user','info','ship'; put 'user', ...
- commonJS — DOM操作(for DOM)
for DOM github: https://github.com/laixiangran/commonJS/blob/master/src/forDOM.js 代码 /** * Created b ...
- ubuntu server samba服务器配置
ubuntu server samba服务器配置 samba可以实现不同操作系统电脑之间的文件共享服务 如:mac os,linux,unix,windows,等 一:安装samba服务器 ubunt ...
- dede 调用四级导航
一.修改文件:\include\taglib目录下的channel.lib.php,请将以下代码全部复制替换上述文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- Web打印使用printThis.js
<script src="~/Content/JQueryTools/printThis/printThis.js"></script>
- hdu-------1081To The Max
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- css背景定位
日期:2015-12-05 背景定位算是才弄明白: background-position:50% 50%; 图片水平和垂直居中.与 background-position:center center ...
- 5月5日 while、do{}while
while .do{}while 一.while的死循环 while (1 == 1)//只要表达式里是true,就是死循环 { //循环内容 } 二.do{}while 不管while是否满足,首先 ...