Results 1 to 3 of 3

Thread: problem with @args

  1. #1
    Join Date
    Jan 2012
    Location
    Poland
    Posts
    2

    Question problem with @args

    Hi
    AOP is something new for me, but i udenrstand most of it. However I have problem with @args. I dont know how to use it.

    I know how to use @annotation, and i thought that it could be similar. I have my annotation like @giveInfo and i use it like this:

    @giveInfo
    public void dummyMtehod() { }
    and have advice

    @Before("@annotation(package.annotation.giveInfo)" )
    public void annotationAdvice(JoinPoint jp) {
    System.out.println("Advice @Before " + jp.getSignature());
    }
    and it work fine.

    So using this i thought to use @args. Class will be like this:

    public void dummyMethod2(@giveINfo int number) {}
    and advice like this:

    @Before("@args(package.annotation.giveInfo)")
    public void annotationAdvice2(JoinPoint jp) {
    System.out.println("Advice @Before " + jp.getSignature());
    }
    it dont make any error at eclipse, but its dont give me any results, so in my opinion its not work good.

    some suggestion?
    maybe simple example of using this?
    i hope knowing how to do @args other (@target, @within) wont be a problem.

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

    Default

    @args have two usage escenarios:

    • Match argument types at runtime annotated with some annotation: @args(javax.persistence.Entity) will match all methods with one argument type when at runtime receive a type annotated with @Entity. ie it will match Dao.save(Book) if Book is a JPA Entity.
    • Bind arguments to advice.


    In your post you want to match calls to execution of a method with annotated parameter, that will be matched with: execution(* *(@SomeAnnotation (*))); Note the parentheses around the wildcard.

    Note: Use code tags for code, no quotes

    Cheers
    Jose Luis Martin
    Freelance Senior Consultant
    JDAL - Java Database Application Library

  3. #3
    Join Date
    Jan 2012
    Location
    Poland
    Posts
    2

    Default

    thank you!

    i use you advice about advice and it work ;-)

    Code:
    public void dummyMethod2(@giveINfoint number) {}
    Code:
    @Before("execution(* *(@giveINfo(*)))")
    public void annotationAdvice2(JoinPoint jp) {
    	System.out.println("Advice @Before " + jp.getSignature());
    }
    i dont know why, but i had big problem to find any full example how to use it... example at documentation of Spring 3.1 wanst good for me

Posting Permissions

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