Intercept a constructor with google guice

依然范特西╮ 提交于 2019-12-13 19:39:29

问题


I want to intercept a constructor with Google guice.

I have added my annotation mark on TYPE but I have some problem with the "bindInterceptor"

If I write

bindInterceptor(Matchers.annotatedWith(ReactToLoad.class),
                Matchers.any(),
                new ReactToLoadInterceptor());

This will run the interceptor on each method. (it's bad and it's normal)

bindInterceptor(                Matchers.any(),
                                Matchers.annotatedWith(ReactToLoad.class),
                new ReactToLoadInterceptor());

If I run the code just below, I MUST put the annotation on the constructor method (it works) but I prefer to put this annotation on top of classes.

I just need a method Matchers for the constuctor method but I don't find it with some googling.

Can you help me ?


回答1:


No, it isn't possible to intercept constructor calls... only method calls. I don't know why you want to do this, but you may want to look in to Guice's SPI, specifically InjectionListener.



来源:https://stackoverflow.com/questions/4781604/intercept-a-constructor-with-google-guice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!