原文地址:http://howtodoinjava.com/spring/spring-aop/writing-spring-aop-aspectj-pointcut-expressions-with-examples/

1) Matching Method Signature Patterns

The most typical pointcut expressions are used to match a number of methods by their signatures.

Matching all methods within a class in another package

For example, the following pointcut expression matches all of the methods declared in the EmployeeManagerinterface. The preceding wildcard matches methods with any modifier (public, protected, and private) and any return type. The two dots in the argument list match any number of arguments.

execution(* com.howtodoinjava.EmployeeManager.*(..))

Matching all methods within a class within same package

You can omit the package name if the target class or interface is located in the same package as this aspect.

execution(* EmployeeManager.*(..))

Matching all public methods in EmployeeManager

Use public keyword in start, and use * to match any return type.

execution(public * EmployeeManager.*(..))

Matching all public methods in EmployeeManager with return type EmployeeDTO

Use public keyword and return type in start.

execution(public EmployeeDTO EmployeeManager.*(..))

Matching all public methods in EmployeeManager with return type EmployeeDTO and first parameter as EmployeeDTO

Use public keyword and return type in start. Also, specify your first parameter as well. Rest parameters can be matched through two dots.

execution(public EmployeeDTO EmployeeManager.*(EmployeeDTO, ..))

Matching all public methods in EmployeeManager with return type EmployeeDTO and definite parameters

Use public keyword and return type in start. Also, specify all parameter types as well.

execution(public EmployeeDTO EmployeeManager.*(EmployeeDTO, Integer))

2) Matching Type Signature Patterns

When applied to Spring AOP, the scope of these pointcuts will be narrowed to matching all method executions within the certain types only.

Matching all methods defined in classes inside package com.howtodoinjava

It’s much like previous example.

within(com.howtodoinjava.*)

Matching all methods defined in classes inside package com.howtodoinjava and classes inside all sub-packages as well

For including, sub-packages use two dots.

within(com.howtodoinjava..*)

Match all methods with a class in another package

Much like previous example using execution keyword.

within(com.howtodoinjava.EmployeeManagerImpl)

Match all methods with a class in same package

In case of same package, drop package name.

within(EmployeeManagerImpl)

Match all methods within all all implementing classes of EmployeeManager interface

Use + (plus) sign to match all implementations of an interface.

within(EmployeeManagerImpl+)

3) Matching Bean Name Patterns

You can match all beans as well having a common naming pattern e.g.

Match all methods defined in beans whose name ends with ‘Manager’.

It’s quite easy one. Use an * to match anything preceding in bean name and then matching word.

bean(*Manager)

4) Combining Pointcut Expressions

In AspectJ, pointcut expressions can be combined with the operators && (and), || (or), and ! (not). e.g.

Match all methods with names ending with Manager and DAO

Use ‘||’ sign to combine both expressions.

bean(*Manager) || bean(*DAO)

I hope that above information will help you when you face any difficulty in determining the correct pointcut expression in your application.

Happy Learning !!

Spring AOP AspectJ Pointcut Expressions With Examples--转的更多相关文章

  1. Spring AOP AspectJ Pointcut 表达式例子

    主要来源:http://howtodoinjava.com/spring/spring-aop/writing-spring-aop-aspectj-pointcut-expressions-with ...

  2. Spring AOP + AspectJ Annotation Example---reference

    In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...

  3. Spring AOP + AspectJ annotation example

    In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...

  4. spring aop中pointcut表达式完整版

    spring aop中pointcut表达式完整版 本文主要介绍spring aop中9种切入点表达式的写法 execute within this target args @target @with ...

  5. 关于 Spring AOP (AspectJ) 该知晓的一切

    关联文章: 关于Spring IOC (DI-依赖注入)你需要知道的一切 关于 Spring AOP (AspectJ) 你该知晓的一切 本篇是年后第一篇博文,由于博主用了不少时间在构思这篇博文,加上 ...

  6. Spring学习(十八)----- Spring AOP+AspectJ注解实例

    我们将向你展示如何将AspectJ注解集成到Spring AOP框架.在这个Spring AOP+ AspectJ 示例中,让您轻松实现拦截方法. 常见AspectJ的注解: @Before – 方法 ...

  7. 关于 Spring AOP (AspectJ) 你该知晓的一切

    版权声明:本文为CSDN博主「zejian_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明.原文链接:https://blog.csdn.net/javazej ...

  8. Spring AOP中pointcut expression表达式解析

    Pointcut 是指那些方法需要被执行"AOP",是由"Pointcut Expression"来描述的. Pointcut可以有下列方式来定义或者通过&am ...

  9. Spring AOP 中@Pointcut的用法

    Spring Aop中@pointCut的用法,格式:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? nam ...

随机推荐

  1. [转] MySQL 查询表数据大小的总结

    一:关于mysql表数据大小 我们知道mysql存储数据文件一般使用表空间存储 当mysql使用innodb存储引擎的时候,mysql使用表存储数据分为共享表空间和独享表空间两种方式 ·共享表空间:I ...

  2. MVC模式下如何实现RegisterStartupScript等功能

    本文源于http://www.achtmaal.com/blog/asp-net-mvc-and-registerclientscriptinclude,非常感谢原文作者的智慧和分享 Register ...

  3. LiveCD DSET日志收集

      DELL的LiveCD是一张PE光盘,最新版本7.1是基于CentOS 6.2系统的. 工具下载地址: http://downloads.dell.com/FOLDER01960516M/1/SL ...

  4. tomcat 运行程序很慢 运行一段时间就报错: java.lang.OutOfMemoryError: PermGen space

    java.lang.OutOfMemoryError: PermGen space 全称是Permanent Generation space,是指内存的永久保存区域. 由于这块内存主要是被JVM存放 ...

  5. libj 0.8.2 发布,Java/JavaScript API 的 C++ 实现

    libj 0.8.2 增加了一些新的字符串相关的方法. libj 是一个跨平台的运行库,相当于提供了类似 Java/JavaScript API.libj 的内存管理是自动的,基于 shared_pt ...

  6. Microsoft .NET Native Developer Preview 内部初探(1)

    Microsoft .NET Native Developer Preview 内部初探(1) MS 前段时间发布了.NET Native Developer Preview,被广大人员赋予“C++的 ...

  7. 【原创】.NET之我见

    最近在准备面试,自己也顺带巩固了下基础,加上自己对码农的一些理解都写在这里了,水平不行,欢迎吐槽 //.NET基础 1.Class 和struct 区别 类是一种“引用类型”.创建类的对象时,对象赋值 ...

  8. 使用Ant自动化我们的java项目生成

    现在我们已经了解如何定义属性.依赖关系以及如何运行ant,接下来我们将学习怎样使用ant编译java源代码并生成jar文件. 编译源代码 由于Ant的主要目标就是生成java应用程序,它内置了java ...

  9. 算法:Astar寻路算法改进

    早前写了一篇<RCP:gef智能寻路算法(A star)> 出现了一点问题. 在AStar算法中,默认寻路起点和终点都是N x N的方格,但如果用在路由上,就会出现问题. 如果,需要连线的 ...

  10. dojo/query源码解析

    dojo/query模块是dojo为开发者提供的dom查询接口.该模块的输出对象是一个使用css选择符来查询dom元素并返回NodeList对象的函数.同时,dojo/query模块也是一个插件,开发 ...