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?

有帮助吗?

解决方案

All i needed was in the configure() method of the WebCoreModule following line:

requestStaticInjection(ClassThatIsUsingInjectedMember.class);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top