<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. 《JS权威指南学习总结--8.5 作为命名空间的函数》

    内容要点:    函数作用域的概念:在函数中声明的变量在整个函数体内都是可见的(包括在嵌套的函数中),在函数的外部是不可见的.不在任何函数内声明的变量是全局变量,在整个JS程序中都是可见的. 在JS中 ...

  2. 【转载】FaceBook - How to add a Privacy Policy to your Apps?

    When you read through the Facebook Platform Policies, you'll notice that every Facebook App that sto ...

  3. JSP+Servlet实现上传下载

    0.项目结构 1.在WebRoot下创建index.jsp页面 <%@ page language="java" import="java.util.*" ...

  4. 京东商品hover效果

    代码: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&q ...

  5. FBO

    #include <GL/glew.h> #include <GL/freeglut.h> #include <iostream> #pragma comment( ...

  6. ZUFE(周赛) 2326 交换字母(STL)

    Time Limit: 1 Sec  Memory Limit: 128 MB Description 有一个长度为n的字符串(只包含小写字母),操作m次,每次操作交换两个字母,输出最终字符串. In ...

  7. PHP中使用CURL(三)

    对 post 提交的数据进行 http_build_query处理,然后再send出去,能实现更好的兼容性,更小的请求数据包. <?php /** * PHP发送Post数据 * @param ...

  8. Excel教程(8) - 财务函数

    ACCRINT 用途:返回定期付息有价证券的应计利息. 语法:ACCRINT(issue,first_interest, settlement, rate,par,frequency, basis) ...

  9. HttpClient模拟get,post请求并发送请求参数(json等)

    import java.io.IOException; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org. ...

  10. ural 1119. Metro(动态规划)

    1119. Metro Time limit: 0.5 second Memory limit: 64 MB Many of SKB Kontur programmers like to get to ...