【问题标题】:Intercept a constructor with google guice使用 google guice 拦截构造函数
【发布时间】:2016-11-17 20:47:36
【问题描述】:

我想用 Google guice 拦截一个构造函数。

我已经在 TYPE 上添加了我的注释标记,但是“bindInterceptor”有一些问题

如果我写

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

这将在每个方法上运行拦截器。 (很糟糕,很正常)

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

如果我运行下面的代码,我必须将注释放在构造函数方法上(它有效),但我更喜欢将此注释放在类之上。

我只需要一个用于构造函数的方法 Matchers,但我没有通过谷歌搜索找到它。

你能帮帮我吗?

【问题讨论】:

    标签: guice


    【解决方案1】:

    不,不可能拦截构造函数调用......只有方法调用。我不知道您为什么要这样做,但您可能想查看 Guice 的 SPI,特别是 InjectionListener

    【讨论】:

    • 7年后还是这样吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    相关资源
    最近更新 更多