I am a new to Guice dependecy injection, hope someone could explain me why my code doesn't work.
here is the class that extends 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. Also I set a breakpoint on getSomeFactory()
method and it is never being invoked.
What am I doing wrong?
我所需要的只是在以下行的WebCoreModule
的configure()
方法中:
requestStaticInjection(ClassThatIsUsingInjectedMember.class);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.