我试图让字段注入工作在谷歌杜松子酒,但是当我调用TestClass.test()注入字段为空。我究竟做错了什么?根据文档字段注射应该是非常直截了当的。在ContextModule类中是否有任何缺失的东西?GWT谷歌领域注射不工作
public class MainEntry implements EntryPoint {
private final ContextInjector injector = GWT.create(ContextInjector.class);
@Override
public void onModuleLoad() {
injector.getAppMain();
}
}
@GinModules(ContextModule.class)
public interface ContextInjector extends Ginjector {
AppMain getAppMain();
}
public class MyLogger {
}
public class ContextModule extends AbstractGinModule {
@Override
protected void configure() {
bind(MyLogger.class).in(Singleton.class);
}
}
public class AppMain {
@Inject
AppMain(MyLogger logger) {
// logger is injected properly here
new TestClass().test();
}
}
public class TestClass {
@Inject
private MyLogger logger;
public void test() {
// logger is null here!
}
}
为什么downvote?我怎样才能改善我的问题? – Sundae 2014-09-25 16:27:59