AspectJ pointcut on constructor object

前端 未结 2 721
醉酒成梦
醉酒成梦 2020-12-05 17:09

I need to inject few methods to every initialized object using AspectJ.

I thought using this :

pointcut vistaInjection(Object o)
    : initializati         


        
2条回答
  •  醉梦人生
    2020-12-05 17:11

    Have you tried

    pointcut vistaInjection(Object o)
        : (initialization(*.new()) || (initialization(*.new(..)))
        && target(o)
        && !within(objectAspect);
    

    i.e. calling .new() on anything and allowing no and some arguments.

    Note - you probably don't want to pick up all object creations.. what are you planning on doing with them!

提交回复
热议问题