我有一个GWT应用程序,它使用Gin/Guice。
我的需要
:在注入所有字段之后调用一个方法。
以下是Javadoc关于
@Inject
Constructors are injected first, followed by fields, and then methods.
所以我的想法是只有一个方法用
@Inject
并将其用作注射后的方法。以下是我的代码摘录:
//An injected attribute (a JSR 303 validator)
@Inject
private Validator validator;
//A constructor with some injectable args.
@Inject
public MyClass(...){
}
//And my post-injection method
@Inject
private void postInjection(){
Log.warn("Validator null? "+(validator==null));
}
问题
:日志显示
true
(=验证器为null,就好像它还没有被注入一样)。稍后,在单击按钮时调用验证器,它看起来是非null的。我测试了其他可注射属性,也有同样的问题。
1)
注射后使用杜松子酒有没有一种常见的模式?
2)
GWT中Gin的注入顺序不同吗?这是个虫子吗?