springAOP 的pointcut
<bean id="amqFilter" class="com.xxx.hotel.base.aspectj.AmQConsumerFilter"/>
<aop:config proxy-target-class="true">
<aop:aspect ref="amqFilter">
<aop:before method="beforeOnMessage" arg-names="message"
pointcut="execution(* xxx.amq.MessageListener.onMessage(..)) and args(message)"/>
</aop:aspect>
</aop:config>
那么pointcut后边的表达式说明了哪些方法需要被aop所执行,可以有args() @args() execution() target() @target() @annotation等来定义或组合(&& , || , !)
其中比较常见的是execution,例子如下:
任意公共方法的执行
execution(public * *(..))
任意一个以get开头的方法的执行
execution(* get*(..))
hotelService接口的任意方法
execution(* com.balfish.hotel.service.HotelService.*(..))
service包里的任意方法的执行
execution(* com.balfish.hotel.service.*.*(..))
service包和所有子包里的任意类的任意方法的执行
execution(* com.balfish.hotel.service..*.*(..))
总结:靠近(..)的是方法,靠近.*(..)的是类或接口
Pointcut 可以通过Java注解和XML两种方式配置,如下所示:
<aop:config>
<aop:aspectref="aspectDemo">
<aop:pointcutid="pointcut"expression="execution(* com.balfish.spring.aop.pointcut..JoinPointTest.*(..))"/>
<aop:before pointcut-ref="pointcut" method="beforeAdvice" />
</aop:aspect>
</aop:config>
@Component
@Aspect
public class AspectDemo {
//@Pointcut("execution(* com.balfish.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
//@Pointcut("within(com.balfish.spring.aop.pointcutexp..*)")
//@Pointcut("this(com.balfish.spring.aop.pointcutexp.Intf)")
//@Pointcut("target(com.balfish.spring.aop.pointcutexp.Intf)")
//@Pointcut("@within(org.springframework.transaction.annotation.Transactional)")
//@Pointcut("@annotation(org.springframework.transaction.annotation.Transactional)")
@Pointcut("args(String)")
public void pointcut() {
}
@Before(value = "pointcut()")
public void beforeAdvice() {
System.out.println("pointcut1 @Before...");
}
springAOP 的pointcut的更多相关文章
- 0 can't find referenced pointcut declarePointExpress
今天在用SpringAOP 的 @pointCut 的时候报错 Exception in thread "main" org.springframework.beans.facto ...
- Spring4.0学习笔记(11) —— Spring AspectJ 的五种通知
Spring AspectJ 一.基于注解的方式配置通知 1.额外引入的jar包: a) com.springsource.org.aopalliance-1.0.0.jar b) com.sprin ...
- spring中AOP的AspectJ的Execution表达式
AspectJ的Execution表达式: 使用springAOP定义pointcut里面的execution表达式: execution()函数是常用的切点函数 "execution(* ...
- [Done]Spring @Pointcut 切点调用不到(SpringAOP嵌套方法不起作用) 注意事项
今天在开发过程中,遇到一个问题卡了很久,测试代码如下: package spring.pointcut; import org.aspectj.lang.ProceedingJoinPoint; im ...
- springAOP注解方式定义切入点报错error at ::0 can't find referenced pointcut
[说明] 1.使用spring版本:4.0.4 2.springAOP相关依赖包: 1)aopalliance-1.0.jar 2)aspectjweaver-1.8.9.jar 3)aspectjr ...
- SpringAOP学习第一天 @Pointcut注解
自从上班之后,就很少再看AOP相关的内容,几年时间里虽然也有一两次完整看过,一直没有机会用到,都忘记了.今天重温一下 TestNG测试类 package com.test.spring.aop.min ...
- jdk1.8+SpringAOP注解报java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut select错误的不知原因的解决办法[仅供参考]
先说办法:如果Aspectweaver-1.*.*jar这三个包版本比较低, 比如1.5.0这一层次的,可以找版本高一点的包替换低版本的包,问题可以得到解决 jar包的下载地址:https://mvn ...
- springAOP配置XML方式配置切面报错error at ::0 formal unbound in pointcut
[错误配置文件] <aop:config> <aop:pointcut expression="execution(* net.fifteenho.service.impl ...
- SpringAOP注解报错:java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut selectAll
原因 我使用的aspectjweaver.jar版本是1.5.1,版本过低,导致报错. 需要下载高本版的aspectjweaver.jar. 解决办法 在这里下载:https://mvnreposit ...
随机推荐
- 《JS权威指南学习总结》
JS权威指南学习总结:http://www.cnblogs.com/ahthw/category/652668.html
- hdu_2296_Ring(AC自动机+DP)
题目链接:hdu_2296_Ring 题意: 有m个字符串,每个字符串有一个价值,现在让你组成一个不超过n长度的字符串,使得价值最大 题解: 很明显是在AC自动机上的DP,设dp[i][j]表示当前长 ...
- strstr() strpos() 获取db报错,判断报错中是否包含字符串,判断错误类型
model中直接获取添加公司的错误.(公司名称不能重复) $enterprise_id = $this->add($enterprisedata ); $err = $this->getD ...
- 安装asterisk
在centos6.5上: yum -y install lynx mysql-server mysql mysql-devel php php-mysql php-mbstring tftp-serv ...
- 抛弃阿里云,中国用户购买海外VPS的五个理由
王掌柜在过去的五年多时间里,折腾过不少vps品牌,最开始玩的是一年一百多块钱的香港虚拟主机,后来业务量大了,开始折腾国内的小鸟云.阿里云.腾讯云.电信云.百度云主机,国外的linode\interse ...
- amazeui tab 监听当前选项
$('#contenttab').find('a').on('opened.tabs.amui', function(e) { if(e.target.pathname.indexOf("[ ...
- Rational Rose 2003 逆向工程转换C++ / VC++ 6.0源代码成UML类图
目录 1.安装&破解Rational Rose 2003 1.1 安装Rose 2003 1.2 破解Rose 2003 1.3运行出错“没有找到suite objects.dl” 2. Ra ...
- <meta http-equiv="X-UA-Compatible" content="IE=Edge">
1.X-UA-Compatible X-UA-Compatible是IE8的一个专有<meta>属性,它告诉IE8采用何种IE版本去渲染网页,在html的<head>标签中使用 ...
- User already has more than 'max_user_connections' active connections
vi /etc/my.cnf修改 max_user_connections 参数的数值,重启 MySQL 服务器
- 网络传输中的三张表,MAC地址表、ARP缓存表以及路由表
一:MAC地址表详解 说到MAC地址表,就不得不说一下交换机的工作原理了,因为交换机是根据MAC地址表转发数据帧的.在交换机中有一张记录着局域网主机MAC地址与交换机接口的对应关系的表,交换机就是根据 ...