Spring AOP target()与this() [英] Spring AOP target() vs this()

查看:446
本文介绍了Spring AOP target()与this()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 Spring文档:

  • 代理的任何连接点(仅在Spring AOP中执行方法) 实现AccountService接口:

  • any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface:

this(com.xyz.service.AccountService)

  • 目标所在的任何连接点(仅在Spring AOP中执行方法) 对象实现AccountService接口:

  • any join point (method execution only in Spring AOP) where the target object implements the AccountService interface:

    target(com.xyz.service.AccountService)
    

  • 我不明白目标对象"和target(...)是什么意思.

    I don't understand what "target object" and the expression target(...) mean.

    targetthis有何不同?

    推荐答案

    this(AType)表示this instanceof AType为true的所有连接点.因此,这意味着在您的情况下,一旦调用到达AccountService this instanceof AccountService的任何方法,该方法将为true.

    this(AType) means all join points where this instanceof AType is true. So this means that in your case once the call reaches any method of AccountService this instanceof AccountService will be true.

    target(AType)表示所有连接点,其中anObject instanceof AType.如果要在对象上调用方法,并且该对象是AccountService的实例,则它将是有效的连接点.

    target(AType) means all join points where anObject instanceof AType . If you are calling a method on an object and that object is an instanceof AccountService, that will be a valid joinpoint.

    总结一种不同的方式-this(AType)是从接收者的角度来看的,而target(AType)是从呼叫者的角度来看的.

    To summarize a different way - this(AType) is from a receivers perspective, and target(AType) is from a callers perspective.

    这篇关于Spring AOP target()与this()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆