Spring AOP - get old field value before calling the setter

前端 未结 2 390
暗喜
暗喜 2020-12-15 14:53

Dear all I am curently using Spring AOP (v4) and AspectJ with load-time-weaver.

I am looking currently for a way to add a dirty flag mechanism into my beans. Therefo

2条回答
  •  半阙折子戏
    2020-12-15 15:19

    You are correct about Spring not supporting field joinpoints

    Spring AOP currently supports only method execution join points (advising the execution of methods on Spring beans). Field interception is not implemented, although support for field interception could be added without breaking the core Spring AOP APIs. If you need to advise field access and update join points, consider a language such as AspectJ.

    You won't be able to use Spring AOP to get the field value through the AOP advice directly.

    A method is not related to any field. Accessors (and mutators) are just a convention in Java. If you are following that convention, you can infer the field name from the method name and use reflection to retrieve it.

提交回复
热议问题