[英]Google Guice. Methods annotated with @Provides annotation are not invoked
I am a new to Guice dependecy injection, hope someone could explain me why my code doesn't work. 我是Guice依赖注入的新手,希望有人可以向我解释为什么我的代码不起作用。
here is the class that extends AbstractModule: 这是扩展AbstractModule的类:
public class WebCoreModule extends AbstractModule {
@Provides
public SomeFactory getSomeFactory() {
return new SomeFactoryImpl();
}
}
and in the other class i have a private member 在另一堂课中,我有一个私人会员
private static @Inject SomeFactory factory;
I'd like to invoke methods on factory
object, but it is always null. 我想在
factory
对象上调用方法,但始终为null。 Also I set a breakpoint on getSomeFactory()
method and it is never being invoked. 另外,我在
getSomeFactory()
方法上设置了一个断点,并且从未调用过该断点。
What am I doing wrong? 我究竟做错了什么?
我所需要的只是在以下行的WebCoreModule
的configure()
方法中:
requestStaticInjection(ClassThatIsUsingInjectedMember.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.