Spring AOP AspectJ Pointcut Expressions With Examples--转
原文地址: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 EmployeeManager
interface. 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--转的更多相关文章
- Spring AOP AspectJ Pointcut 表达式例子
主要来源:http://howtodoinjava.com/spring/spring-aop/writing-spring-aop-aspectj-pointcut-expressions-with ...
- Spring AOP + AspectJ Annotation Example---reference
In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...
- Spring AOP + AspectJ annotation example
In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...
- spring aop中pointcut表达式完整版
spring aop中pointcut表达式完整版 本文主要介绍spring aop中9种切入点表达式的写法 execute within this target args @target @with ...
- 关于 Spring AOP (AspectJ) 该知晓的一切
关联文章: 关于Spring IOC (DI-依赖注入)你需要知道的一切 关于 Spring AOP (AspectJ) 你该知晓的一切 本篇是年后第一篇博文,由于博主用了不少时间在构思这篇博文,加上 ...
- Spring学习(十八)----- Spring AOP+AspectJ注解实例
我们将向你展示如何将AspectJ注解集成到Spring AOP框架.在这个Spring AOP+ AspectJ 示例中,让您轻松实现拦截方法. 常见AspectJ的注解: @Before – 方法 ...
- 关于 Spring AOP (AspectJ) 你该知晓的一切
版权声明:本文为CSDN博主「zejian_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明.原文链接:https://blog.csdn.net/javazej ...
- Spring AOP中pointcut expression表达式解析
Pointcut 是指那些方法需要被执行"AOP",是由"Pointcut Expression"来描述的. Pointcut可以有下列方式来定义或者通过&am ...
- Spring AOP 中@Pointcut的用法
Spring Aop中@pointCut的用法,格式:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? nam ...
随机推荐
- Go+sublime text3的环境搭建
1.安装Go语言. .msi下载地址:http://download.csdn.net/detail/u014075041/9555543 根据提示安装成功! 在命令行中执行 go env 有提示 ...
- 读bootstrap2.3.2有感2
排版: Bootstrap定义的全局 font-size 是 14px,line-height 是 20px.这些样式应用到了 <body> 和所有的段落上.另外,对 <p> ...
- [poi2010]Hamsters
题意:Tz养了一群仓鼠,他们都有英文小写的名字,现在Tz想用一个字母序列来表示他们的名字,只要他们的名字是字母序列中的一个子串就算,出现多次可以重复计算.现在Tz想好了要出现多少个名字,请你求出最短的 ...
- CentOS7 bonding配置
操作系统:CentOS Linux release 7.1.1503 (Core) 网卡适配器: eno1.eno2 bonding类型:mode=1 (active-backup),主-备份策略 网 ...
- highcharts 柱状图 折线图 混合 双纵轴显示
$(function () { $('#container').highcharts({ chart: { zoomType: 'xy' }, title: { text: '' }, colors: ...
- PHP学习第一天笔记——php的基本语法
1.php嵌入到html中的方式 (1) <?php.....?> 标准风格(推荐) (2)<script language="php">......< ...
- 完美实现类似QQ的自拍头像、上传头像功能!(Demo 源码)
现在很多下载客户端程序都需要设定自己头像的功能,而设定头像一般有两种方式:使用摄像头自拍头像,或者选择一个图片的某部分区域作为自己的头像. 一.相关技术 若要实现上述的自拍头像和上传头像的功能,会碰到 ...
- 接口分离原则(Interface Segregation Principle)
接口分离原则(Interface Segregation Principle)用于处理胖接口(fat interface)所带来的问题.如果类的接口定义暴露了过多的行为,则说明这个类的接口定义内聚程度 ...
- web前端职业规划(转)
关于一个WEB前端的职业规划,其实是有各种的答案,没有哪种答案是完全正确的,全凭自己的选择,只要是自己选定了, 坚持去认真走,就好.在这里,我只是简要说一下自己对于这块儿内容的理解.有一个观点想要分享 ...
- FusionCharts简单教程(八)-----使用网格组件
有时候我们会觉得使用图像不够直接,对于数据的显示没有表格那样直接明了.所以这里就介绍如何使用网格组件.将网格与图像结合起来.网格组件能够将FusionCharts中的单序列数据以列表的 ...