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 ...
随机推荐
- IE中float元素如果同时设置了margin值,此时margin的值会变为双倍的解决方法
IE中float元素如果同时设置了margin值,此时margin的值会变为双倍, 解决办法: 是在该元素中加入display:inline.
- 戏说HTML5(转)
如果有非技术人员问你,HTML5是什么,你会怎么回答? 新的HTML规范... 给浏览器提供了牛逼能力,干以前不能干的事...(确切地说应该是给浏览器规定了许多新的接口标准,要求浏览器实现牛逼的功能. ...
- c语言正则表达式
标准的C和C++都不支持正则表达式,但有一些函数库可以辅助C/C++程序员完成这一功能,其中最著名的当数Philip Hazel的Perl-Compatible Regular Expression库 ...
- hdu_5314_Happy King(树的点分治)
题目链接:hdu_5314_Happy King 题意: 给出一颗n个结点的树,点上有权值: 求点对(x,y)满足x!=y且x到y的路径上最大值与最小值的差<=D: 题解: 还是树的点分治,在统 ...
- Redis持久存储-AOF&RDB
Redis中数据存储模式有2种:cache-only,persistence;cache-only即只做为"缓存"服务,不持久数据,数据在服务终止后将消失,此模式下也将不存在&qu ...
- ESFramework 4.0 快速上手(01) -- Rapid引擎
(在阅读该文之前,请先阅读 ESFramework 4.0 概述 ,会对本文的理解更有帮助.) ESFramework/ESPlatform 4.0 的终极目标是为百万级的用户同时在线提供支持,因为强 ...
- velocity的宏
velocity中的宏macro的使用当中,由于velocity会将宏加载到tomcat中去,但是如果修改之后再加载的话velocity发现有了相同的宏名称,则不会加载 所以这时候的问题就是,在页面上 ...
- SQL_where条件的优化
原则,多数数据库都是从 左到右的顺序处理条件,把能过滤更多数据的条件放在前面,过滤少的条件放后面 SQL1: select * from employee where sala ...
- tableviewcell 中使用autolayout自适应高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { [ce ...
- redis数据类型:lists
redis的list类型其实就是一个每个子元素都是string类型的双向链表. 我们可以通过push,pop操作从链表的头部或者尾部添加删除元素,这样list即可以作为 栈,又可以作为队列. lpus ...