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 ...
随机推荐
- 经典排序算法(PHP)
1.冒泡算法,排序算法,由于在排序过程中总是小数往前放,大数往后放,相当于气泡往上升,所以称作冒泡排序 function maopao_fun($array){ $count = count($arr ...
- mysql获取所有分类的前n条记录的两种方法浅析
项目中有个需求是获取出展会分类下的前n条展商. 刚开始的思路是用group by 获取出展会的分类,后面再根据分类获取该分类下的n个展商,但也需要第一次获取出展会的时候也获取所有的每个展会分类下的 ...
- 20145301&20145321&20145335实验三
20145301&20145321&20145335实验三 这次实验我的组员为:20145301赵嘉鑫.20145321曾子誉.20145335郝昊 实验内容详见:实验三
- java war包加载提示jar not loaded
今天在开发的时候,项目需要加载Guvnor的war包.War包部署后,启动tomcat提示jar not load 后来查阅资料后发现是Jar包冲突导致的,冲突的Jar包在tomcat中已经存在,然后 ...
- Atom.io设置ctrl+delete
一般常见的text editor,在文本前面的空白处按下ctrl+delete,只是删除空白符到单词前面停下,但是Atom.io的默认设置,把空白符后遇到的第一个单词也删掉了.改配置方法是在keyma ...
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- Spring1:Spring简介、环境搭建、源码下载及导入MyEclipse
框架学习前言 这个模块是面向Spring的,Spring的学习我是这么想的: 1.简单介绍Spring,主要是从网上借鉴一些重点 2.尽量说明清楚Spring的使用方法以及细节点 3.尽量以自己的理解 ...
- jquery插件——点击交换元素位置(带动画效果)
一.需求的诞生 在我们的网页或者web应用中,想要对列表中的元素进行位置调整(或者说排序)是一个常见的需求.实现方式大概就以下两种,一种是带有类似“上移”.“下移”的按钮,点击可与相邻元素交换位置,另 ...
- java提高篇(二四)-----HashSet
在前篇博文中(java提高篇(二三)-----HashMap)详细讲解了HashMap的实现过程,对于HashSet而言,它是基于HashMap来实现的,底层采用HashMap来保存元素. ...
- 虚拟化平台cloudstack(7)——新版本的调试
调试环境 ubuntu 12.04 JDK1.7 apache-maven-3.10 eclipse 4.2 Juno mysql 5 源码下载及调试 上面的几个软件在上一篇中已经介绍了. 在新的版本 ...