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 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--转的更多相关文章
- 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 ...
随机推荐
- SQL SERVER 2000数据库置疑处理
由于服务器意外的断电,导致SQL SERVER服务器上数据库出现“置疑”而无法使用,通过网上搜索,找到以下方法解决问题,这里记录一下: 产生数据库置疑的时侯,数据库文件和日志文件都是存在的,如果数据库 ...
- 好用的SQL TVP~~独家赠送[增-删-改-查]的例子
以前总是追求新东西,发现基础才是最重要的,今年主要的目标是精通SQL查询和SQL性能优化. 本系列主要是针对T-SQL的总结. [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础] ...
- 走进AngularJs(八) ng的路由机制
在谈路由机制前有必要先提一下现在比较流行的单页面应用,就是所谓的single page APP.为了实现无刷新的视图切换,我们通常会用ajax请求从后台取数据,然后套上HTML模板渲染在页面上,然而a ...
- Java提高篇(三六)-----Java集合细节(二):asList的缺陷
在实际开发过程中我们经常使用asList讲数组转换为List,这个方法使用起来非常方便,但是asList方法存在几个缺陷: 一.避免使用基本数据类型数组转换为列表 使用8个基本类型数组转换为列表时会存 ...
- 论checkbox和radio的样式美化问题
如果你下定决心要改变现有的默认的checkbox和radio的样式,那么我目前有两种办法: 1.自己动手写一个,也就是自己写代码实现将input的checkbox和radio默认的样式隐藏掉,使用绝对 ...
- Windows UDP socket recvfrom返回10054错误的解决办法
现象: 在Windows 7系统上,A使用UDP socket,调用sendto函数向一个目标地址B发送数据,但是目标地址B没有接收数据,如果A此时立即调用recvfrom试图接收目标地址B发回的数据 ...
- AWS re:Invent 2014回顾
亚马逊在2014年11月11-14日的拉斯维加斯举行了一年一度的re:Invent大会.在今年的大会上,亚马逊一股脑发布和更新了很多服务.现在就由我来带领大家了解一下这些新服务. 安全及规范相关 AW ...
- 跨站脚本攻击XSS
跨站脚本攻击(Cross Site Script为了区别于CSS简称为XSS)指的是恶意攻击者往Web页面里插入恶意html代码,当用户浏览该页之时,嵌入其中Web里面的html代码会被执行,从而达到 ...
- Lucene系列-概述
为了生存,就得干一行爱一行.那就学习下lucene吧. 全文检索介绍 流程: 建索引 准备待搜索文档 文档分词:将文档分成一个个单独的单词,去除标点符号.停词(无意义的冠词介词等),得到token 语 ...
- Sizeof的计算看内存分配
本文记录了有关sizeof的一些计算,主要有下面的四种情况:(如有错误,敬请留言) 使用sizeof()计算普通变量所占用的内存空间 sizeof计算类对象所占用空间的大小-用到了字节对齐 sixeo ...