Results 1 to 2 of 2

Thread: Pointcut on a class annotation whith determined value

  1. #1
    Join Date
    Dec 2010
    Location
    Tehran
    Posts
    48

    Cool Pointcut on a class annotation whith determined value

    I need to define a pointcut on a class annotation with determined value.
    such a thing:
    Code:
    @LogMe(LogginLevel.INFO)
    class foo{
    
    void bar()
    ...
    }
    This works for such a pointcut but on method annotation:
    Code:
    execution(@com.tosan.LogMe(com.tosan.LoggingLevel.INFO) * *(..))
    And these work for a class annotation but without any value:
    Code:
    execution(* *(..)) && within(@com.tosan.LogMe *)
    execution(* *(..)) && @within(com.tosan.LogMe)
    And these combined expressions fail:
    Code:
    execution(* *(..)) && within(@com.tosan.LogMe(com.tosan.LoggingLevel.INFO) *)
    execution(* *(..)) && within(@com.tosan.LogMe(com.tosan.LoggingLevel.INFO) ..*)
    
    execution(* *(..)) && @within(com.tosan.LogMe(com.tosan.LoggingLevel.INFO) *)
    execution(* *(..)) && @within(com.tosan.LogMe(com.tosan.LoggingLevel.INFO) ..*)
    Last edited by mjafari; Feb 5th, 2012 at 09:05 AM.

  2. #2
    Join Date
    Apr 2008
    Location
    Seville, Spain
    Posts
    132

    Default

    Use if to match on annotation values:

    .. && @target(logMe) && if(logMe.value() == LogginLevel.INFO)

    but you need to use AspectJ, Spring AOP don't support the 'if' poincut designator.

    Cheers
    Last edited by chelu; Feb 7th, 2012 at 03:54 AM.
    Jose Luis Martin
    Freelance Senior Consultant
    JDAL - Java Database Application Library

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
  •