博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring AOP AspectJ Pointcut Expressions With Examples--转
阅读量:6980 次
发布时间:2019-06-27

本文共 3382 字,大约阅读时间需要 11 分钟。

原文地址: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 , 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 !!

转载地址:http://fvjpl.baihongyu.com/

你可能感兴趣的文章
Enterprise Library 2.0 Hands On Lab 翻译(15):加密应用程序块(二)
查看>>
帮助电力,轻松实现运维管理
查看>>
三地跨区域链路 汇聚统一监控平台——国际化综合性顾问咨询公司阿特金斯
查看>>
SQL SERVER与MYSQL 的重复插入的区别
查看>>
cocos2d-x学习笔记09:动作2:持续动作
查看>>
网络嗅探软件全接触(2)
查看>>
J0ker的CISSP之路:复习-Information Security Management(4)
查看>>
使用CSS 3创建不规则图形
查看>>
SCOM 2007 R2监控系统安装部署(三)安装SCOM报表服务器和审计服务器
查看>>
服务契约
查看>>
Lync Server 2010标准版系列PART6:启用Lync
查看>>
.net framework3.5新特性1:Lambda表达式
查看>>
虚拟化系列-Citrix XenServer 6.1 网络管理
查看>>
是谁令我离开生活了16年的广州
查看>>
MySQL数据库的主从同步实现及应用
查看>>
阿里游戏云与Intel,iTechClub以及巨人网络共同发布的“TOP游戏”云生态培育计划合作...
查看>>
Hyper-V2:向VM增加虚拟硬盘
查看>>
解决 vs2010 安装过程 提示序列号非法问题
查看>>
flask, SQLAlchemy, sqlite3 实现 RESTful API 的 todo list, 同时支持form操作
查看>>
[转载]AxureRP 7超强部件库下载
查看>>