标签: java guice
我试图通过Google Guice @Inject注释注入一些服务:
@Inject Service service;
此注入工作正常,但并非在所有地方都有效。当它没有工作时我捕获空指针。有什么问题?显然,所有的尝试都在单个项目中
答案 0 :(得分:3)
If you do not create your instances with .getInstance() nothing will be injected. The annotation is not magic.
.getInstance()
You have to use requestStaticInjection() on static references that are annotated with @Inject.
requestStaticInjection()
static
@Inject
This is all explained in extreme detail in the Guice documentation.