Results 1 to 2 of 2

Thread: Need to apply an advice to method of interface regardless implementing class

  1. #1

    Question Need to apply an advice to method of interface regardless implementing class

    Hi Guys...

    just want to put an advice to a method of an interface, not class. I mean, whenever the one method e.g. addName() of an interface "MyInterface" invoked through some implementing class object, an advice on that method will run.
    If this is possible then we can minimize no. of proxy object on every implementing class.


    --------------------------------------------------------------------------------
    e.g:

    interface myInterface{ public void addMyName(String name); }

    class SomeMyClass implements myInterface {
    public void addName(String name){

    //.....

    }
    }

    @Aspect
    class myInterfaceProxy implements BeforeAdvice{

    @Before("execute(* com.myInterface.addName(..))")
    public void before(Method arg0, Object[] arg1, Object arg2){

    //...
    }
    }


    -----------------------------------------------------------------

  2. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    You can do pointcut matching to interface methods. All beans implementing the interface will be proxied. I don't understand what do you mean by minimizing proxy objects. Intefaces cannot be proxied, class instances are. Pointcut matching to interfaces is just a way to make configuration simple (you don't have to list all implementations in a pointcut).

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
  •