<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的更多相关文章

  1. 0 can't find referenced pointcut declarePointExpress

    今天在用SpringAOP 的 @pointCut 的时候报错 Exception in thread "main" org.springframework.beans.facto ...

  2. Spring4.0学习笔记(11) —— Spring AspectJ 的五种通知

    Spring AspectJ 一.基于注解的方式配置通知 1.额外引入的jar包: a) com.springsource.org.aopalliance-1.0.0.jar b) com.sprin ...

  3. spring中AOP的AspectJ的Execution表达式

    AspectJ的Execution表达式: 使用springAOP定义pointcut里面的execution表达式: execution()函数是常用的切点函数 "execution(* ...

  4. [Done]Spring @Pointcut 切点调用不到(SpringAOP嵌套方法不起作用) 注意事项

    今天在开发过程中,遇到一个问题卡了很久,测试代码如下: package spring.pointcut; import org.aspectj.lang.ProceedingJoinPoint; im ...

  5. 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 ...

  6. SpringAOP学习第一天 @Pointcut注解

    自从上班之后,就很少再看AOP相关的内容,几年时间里虽然也有一两次完整看过,一直没有机会用到,都忘记了.今天重温一下 TestNG测试类 package com.test.spring.aop.min ...

  7. jdk1.8+SpringAOP注解报java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut select错误的不知原因的解决办法[仅供参考]

    先说办法:如果Aspectweaver-1.*.*jar这三个包版本比较低, 比如1.5.0这一层次的,可以找版本高一点的包替换低版本的包,问题可以得到解决 jar包的下载地址:https://mvn ...

  8. springAOP配置XML方式配置切面报错error at ::0 formal unbound in pointcut

    [错误配置文件] <aop:config> <aop:pointcut expression="execution(* net.fifteenho.service.impl ...

  9. SpringAOP注解报错:java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut selectAll

    原因 我使用的aspectjweaver.jar版本是1.5.1,版本过低,导致报错. 需要下载高本版的aspectjweaver.jar. 解决办法 在这里下载:https://mvnreposit ...

随机推荐

  1. Intellij Idea web项目的部署配置[转]

    原文地址:http://blog.csdn.net/z69183787/article/details/41416189 1.前言 2.项目配置(Project Structure) 2.1 Proj ...

  2. hdfs zkfc –formatZK 之HadoopIllegalArgumentException: Bad argument: –formatZK

    HadoopIllegalArgumentException: Bad argument: –formatZK从某文档中拷贝的命令,粘贴过来使用的,“–formatZK”有问题解决方法:手工输入此命令 ...

  3. navicat 连接远程mysql

    01putty中session---远程地址(程序访问的域名) ,端口22--load加载进来 02SSH--Auth-Tunnels(隧道)-- putty端口映射SSH--Auth-Tunnels ...

  4. c++的复制构造函数

    在C++中,下面三种对象需要调用拷贝构造函数(有时也称“复制构造函数”): 1) 一个对象作为函数参数,以值传递的方式传入函数体: 2) 一个对象作为函数返回值,以值传递的方式从函数返回: 3) 一个 ...

  5. Codeforces Round #256 (Div. 2) B Suffix Structures

    Description Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" t ...

  6. ural 1091. Tmutarakan Exams(容斥原理)

    1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...

  7. hadoop namespace

    As underscore(_) is not allowed. It may be the problem if your other configuration are ok. Your conf ...

  8. 实现ie6下的居中

    代码如下所示,转自 http://w3help.org/zh-cn/causes/RT8003 对于 text-align 的讨论. <div style="width:200px; ...

  9. HTML+CSS Day10实例

    1.家居大视野 效果图: 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  10. oracle日期的处理

    字符长转换为日期,有两种写法 SELECT date'2016-06-03' FROM dualselect to_date('2016-06-03','yyyy-mm-dd') from dual ...