Announcement Announcement Module
Collapse
No announcement yet.
Why AOP doesn't intercept this method implementing an interface? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why AOP doesn't intercept this method implementing an interface?

    I have the Command interface:
    public interface Command<A extends Action> {
    public Response execute(A action);
    }

    The LoginCommand class:
    public class LoginCommand implements Command<LoginAction>{
    public Response execute(LoginAction action){}
    }
    LoginAction extends Action.

    The AOP config:
    <aop:config proxy-target-class="true">
    <aop:aspect id="logging" ref="loggingAspect">
    <aop:before
    pointcut="execution(* command.LoginCommand.*(..))"
    method="doBeforeCommandAccess"/>
    </aop:aspect>
    </aop:config>

    Before LoginCommand.execute(), the doBeforeCommandAccess() is not run.

    However, if I modify the LoginCommand.execute to be
    public Response execute(Action action){}
    The doBeforeCommandAccess() runs before the method.

    I am wondering when the target class implements some interface, is it required that the concrete class has the exact method signature as that in the interface? Is there any way around it? Please note, that I get the same result with or without proxy-target-class="true". So CGLIB proxy or Jdk dynamic proxy don't seem to be different in this case.

    Thank you very much.

  • #2
    Please help!

    Could anyone please help?

    I checked out the Spring document. It says:

    If the target object to be proxied implements at least one interface then a JDK dynamic proxy will be used. All of the interfaces implemented by the target type will be proxied. CGLIB proxying is to proxy every method defined for the target object, not just those implemented by its interfaces.

    In my case, I would think
    LoginCommand implements the Command interface. (as least the Compiler says so)
    Command:
    public interface Command<A extends Action> {
    public Response execute(A action);
    }

    LoginCommand:
    public Response<String> execute(LoginAction action)

    However, JDK dynamic proxy doesn't intercept the execute method. Then I forced it to use CGLIB, it is also not intercepted.

    Comment


    • #3
      Fixed.

      My problem is fixed when I replaced with the latest 2.0.7 spring.jar. Thank you for everyone who viewed my post.

      Comment

      Working...
      X