开发者

My @Around advice is not being called for all the methods in the package

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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜