Google GIN,GWT和com.google.inject.Inject(optional = true)无效

时间:2017-10-04 15:56:58

标签: java gwt guice gwtp gin

我有一个GIN @Inject调用,我使用optional=true属性,但它没有被尊重/不工作(并且因为我的类没有绑定而抛出错误,这是真的)。

我通过.gwt.xml文件使用GIN,如下所示:

<extend-configuration-property name="gin.ginjector.modules" value="com.example.client.ClientModule" />

在上面的示例中,ClientModule扩展了com.google.gwt.inject.client.AbstractGinModule

然后我有一个班级,我requestStaticInjection喜欢这样: requestStaticInjection(Example.class);

Example.java我有:

class Example {
        @com.google.inject.Inject(optional=true)
        protected static SomeUnboundInterface someUnboundInterface = null;
...
}

但我在应用启动过程中遇到错误:

[INFO]             [ERROR] No binding found for com.example.SomeUnboundInterface in com.gwtplatform.mvp.client.DesktopGinjector
[INFO]    [ERROR] Errors in 'gen/com/gwtplatform/mvp/client/DesktopGinjectorProvider.java'
[INFO]       [ERROR] Line 8: Failed to resolve 'com.gwtplatform.mvp.client.DesktopGinjector' via deferred binding

嗯,这确实是真的;我的SomeUnboundInterface确实没有绑定;但我希望使用optional=true属性可行。

请注意,官方文档并未说明对于GIN,此属性受支持。但是,it does say so for GUICE,所以我希望它也适用于GIN。

您是否知道任何解决方案,以便在未绑定特定依赖项时我不会收到错误?

编辑:忘了提及版本。 GWT 2.8.1; GIN 2.1; GWTP 1.6

1 个答案:

答案 0 :(得分:0)

可选应该有用,这个例子编译并打印&#39; null&#39;使用GWT 2.8.1和GIN 2.1.2。

d=d.append(sth)


import sys
def find_common(a,b,c):
    d=[]
    for i in a:
        if i in b:
            d=d.append(i)
    for i in d:
        if i not in c:
            c=c.append(i)
    print(c)
    return c

if __name__ == '__main__':
    a=[1,1,2,4]
    b=[2,2,3,4]
    c=[]
    find_common(a,b,c)
    sys.exit()

但是如果你添加一个静态注入,就像在你的例子中一样,它会失败。您可以将其绑定到某个内容或删除&#34; requestStaticInjection&#34;。

相关问题