views:

29

answers:

1

Hi,

I have this code below in my LoggingAspect class and i am expect this to run for my methods like

gov.ssa.rome.service.impl.save() gov.ssa.rome.dao.impl.save()

but it is running only one time no matter what. i don't know why. i have used autowire to wire dao to servcice layer. I really appreciate your help.

what should i do to make this method run for all my application flow to see the flow in logs?

@Around("execution(* gov.ssa.rome..*.*(..))")
public Object log(ProceedingJoinPoint pjp) throws Throwable {

 System.out.println("aspect Around started");

        Object ret = pjp.proceed();

    System.out.println("aspect Around ended);

  return ret;
}
+1  A: 

Aspects can be created using different technologies. If yours are JDK proxies, they will work only for methods defined in an interface. If they are cglib proxies, they will work for all but final methods. I think spring by default will use JDK proxy if matching class implements an interface and cglib proxy otherwise.

Check what your class with save method looks like and whether save comes from an interface. You can enforce aspectjweaver proxies to make everything work, but they require some bytecode manipulation. I would recommend sticking to JDK proxies and creating/extending interfaces where needed. Refer to spring documentation AOP chapter for more information.

mrembisz