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 ...
 
随机推荐
- Html总结及日志目录
			
Html就是超文本标记语言的简写,是最基础的网页语言,代码都是由标签所组成,不用区分大小写. 1. Html代码由<html>开始</html>结束.里面由头部分<hea ...
 - JavaScript中String的math方法与RegExp的exec方法的区别
			
1.exec是正则表达式的方法,方法参数为字符串.match为字符串的方法,参数为正则表达式对象. 2.match与exec都返回数组.如果调用exec方法的正则表达式没有分组内容,则返回第一个匹配的 ...
 - zabbix3.x搭建(1)
			
服务器端安装配置: 1).安装: yum -y install gcc gcc-c++ autoconf httpd php mysql mysql-server php-mysql httpd-ma ...
 - javascript Xml兼容性随笔
			
一.前言 (function (window) { if (!window.jasen) { window.jasen = {}; } if (!window.jasen.core) { window ...
 - Ember.js之动态创建模型
			
本人原文地址发布在:点击这里 What problem did we meet? As ember document suggestion, we may define a model as a st ...
 - 《JAVA与模式》之抽象工厂模式
			
场景问题 举个生活中常见的例子——组装电脑,我们在组装电脑的时候,通常需要选择一系列的配件,比如CPU.硬盘.内存.主板.电源.机箱等.为讨论使用简单点,只考虑选择CPU和主板的问题. 事实上,在选择 ...
 - 【腾讯Bugly干货分享】深入源码探索 ReactNative 通信机制
			
Bugly 技术干货系列内容主要涉及移动开发方向,是由 Bugly 邀请腾讯内部各位技术大咖,通过日常工作经验的总结以及感悟撰写而成,内容均属原创,转载请标明出处. 本文从源码角度剖析 RNA 中 J ...
 - Java多线程21:多线程下的其他组件之CyclicBarrier、Callable、Future和FutureTask
			
CyclicBarrier 接着讲多线程下的其他组件,第一个要讲的就是CyclicBarrier.CyclicBarrier从字面理解是指循环屏障,它可以协同多个线程,让多个线程在这个屏障前等待,直到 ...
 - Java提高篇(二六)-----hashCode
			
在前面三篇博文中LZ讲解了(HashMap.HashSet.HashTable),在其中LZ不断地讲解他们的put和get方法,在这两个方法中计算key的hashCode应该是最重要也是最 ...
 - [译]C++, Java和C#的编译过程解析
			
1.1.1 摘要 我们知道计算机不能直接理解高级语言,它只能理解机器语言,所以我们必须要把高级语言翻译成机器语言,这样计算机才能执行高级语言编写的程序,在接下来的博文中,我们将介绍非托管和托管语音的编 ...