Announcement Announcement Module
No announcement yet.
problem with @args Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with @args

    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:

    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:

    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
    @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 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



    • #3
      thank you!

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

      public void dummyMethod2(@giveINfoint number) {}
      @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