Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to define a pointcut for intercepting setter using annotation at field level.

There are two issues here.  First, your annotations are on the field
yet you want to advise the methods.  You will either have to move your
annotations to the methods, or advise the field set.

The second part is to exclude all fields/methods with the annotation
on it.  Here is a way to do this with field sets

      public pointcut noAuditValueChange(AbstractBusinessEntity entity) :
        set ( @DoNotAudit * AbstractBusinessEntity +.*) && target(entity);

      public pointcut auditValueChange(AbstractBusinessEntity entity) :
        execution ( @DoNotAudit * AbstractBusinessEntity +.*) &&
target(entity) &&
        !noAuditValueChange(entity) ;

Note, I haven't tried this out, so the syntax might be slightly off.

Also, if you only want to advise field sets that occur within setter
methods, you can add a withincode clause to your pointcut.

--a


Back to the top