简体   繁体   English

Google Guice。 用@Provides注释注释的方法不会被调用

[英]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? 我究竟做错了什么?

我所需要的只是在以下行的WebCoreModuleconfigure()方法中:

requestStaticInjection(ClassThatIsUsingInjectedMember.class);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM