Announcement Announcement Module
Collapse
No announcement yet.
Difference between this and target in Spring AOP? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference between this and target in Spring AOP?

    Hi,

    As per the documentation in section 6.2.3.1
    this - limits matching to join points (the execution of methods when using Spring AOP) where the bean reference (Spring AOP proxy) is an instance of the given type

    target - limits matching to join points (the execution of methods when using Spring AOP) where the target object (application object being proxied) is an instance of the given type
    While I understand the 2 statements in essence, what confuses me is the benefit of these 2 being separately spelled out in Spring, since in Spring AOP all target objects in Spring AOP would always be proxied, as per section 6.1.1 of the documentation,

    Target object: object being advised by one or more aspects. Also referred to as the advised object. Since Spring AOP is implemented using runtime proxies, this object will always be a proxied object.
    -Yazad Khambata

  • #2
    I read the Introductions section and saw an example on use of this, and everything started to fall in place. Thanks my question is answered I guess!
    Code:
    @Aspect
    public class UsageTracking {
    
      @DeclareParents(value="com.xzy.myapp.service.*+",
                      defaultImpl=DefaultUsageTracked.class)
      public static UsageTracked mixin;
      
      @Before("com.xyz.myapp.SystemArchitecture.businessService() &&" +
              "this(usageTracked)")
      public void recordUsage(UsageTracked usageTracked) {
        usageTracked.incrementUseCount();
      }
      
    }
    It's "this" that implements UsageTracked and NOT "target"!

    Comment

    Working...
    X