Results 1 to 2 of 2

Thread: Difference between this and target in Spring AOP?

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Question 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. #2
    Join Date
    Feb 2012
    Posts
    2

    Lightbulb

    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"!
    Yazad Khambata

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •