Java: How to listen on methods invocation without registering each object explicitely?

前端 未结 3 995
旧时难觅i
旧时难觅i 2021-01-26 11:42

I want to listen on method calls in order to attach additional behavior dynamically around the call. I\'ve already done it on JUnit methods with a custom annotation and runner.

3条回答
  •  执念已碎
    2021-01-26 12:22

    Well,this is commonly seen with Spring Framework and Aspect Oriented Programming. Since you delegate your constructor calls to Spring, it is quite easy for Spring to put a proxy in place to intercept calls to the actual objects.

    As far as I can tell, the only way to intercept calls is to use a proxy. Either in the way you mentioned or using Spring and AOP.

提交回复
热议问题