扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共4页)
7. execution 和call join point 的区别
我的理解是:
1) 在你想针对某个方法进行某些advice的织入时,应该用execution,即当想在某个方法的方法体之前,之后,之中织入某些advice时使用。
Example:
在这段代码中,如果想在debit()的方法体,即
之前、之后、之中织入一些advice时使用。
2) 而call是想在调用某个方法的地方之前、之后织入某些advice时使用的。
Example:
Account account = …...;
account.debit(100); //即在句前、后加advice时使用。
8. Execution Object Pointcuts (this和target)
1) These pointcuts match the join points based on the types of the objects at execution time.
这种pointcut用于在运行期匹配对象的类型。
2) In addition to matching the join points, these pointcuts are used to collect the context at the specified join point.
另外,这种pointcut可以用于收集join point附近的上下文信息。
3) The this() pointcut takes the form this(Type or ObjectIdentifier); it matches all join points that have a this object associated with them that is of the specified type or the specified ObjectIdentifier’s type. In other words, if you specify Type, it will match the join points where the expression this instanceof <Type> is true. The form of this pointcut that specifies ObjectIdentifier is used to collect the this object. If you need to match without collecting context, you will use the form that uses Type, but if you need to collect the context, you will use the form that uses ObjectIdentifier.
this() 型pointcut的基本形式为this(Type or ObjectIdentifier);它匹配所有有this对象的pointcut,而这些pointcut就是已声明的类型或对象标识符的类型。换句话说就是,如果你声明了Type,当表达式this instanceof <Type>为真时将匹配。声明为ObjectIdentifier的pointcut将用于收集this对象的上下文信息。如果你想只匹配而不收集上下文,可以使用Type,反之则使用ObjectIdentifier
4) The target() pointcut is similar to the this () pointcut. The target() pointcut is normally used with a method call join point.
target() pointcut 和this() pointcut类似。target() pointcut 一般和call join point 搭配使用。
5) Example:
this(Account) All join points where this is instanceof Account. This will match all join points like methods calls and field assignments where the current execution object is Account, or its subclass, for example, SavingsAccount.
target(Account) All the join points where the object on which the method called is instanceof Account. This will match all join points where the target object is Account, or its subclass, for example, SavingsAccount.
6) target 匹配的是哪个对象调用了某方法
Example:
ResgisterBuiness rb = new ResgisterBuiness();
forwardName = rb.doRegister(mapping.form);
对于doRegister方法来说,rb就是target
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者