Is it possible to use dagger2 with jersey the same way it is possible with guice?

半世苍凉 提交于 2020-01-01 19:02:12

问题


Is it possible to use dagger2 with jersey the same way it is possible with guice?

Is there any dagger2 servlet or dagger2 jersey project?


回答1:


So, short answer is no, there is not a great way to do this while getting all of the features of Jersey in your application.

However, there are ways to partially do this. You can simply register your resource in an application servlet ( see an example of that here https://github.com/cogman/gluews/blob/master/src/main/java/com/cogman/glue/GlueApplication.java )

What you lose with this approach are the Jersey injected magic things at the field level, such as @Context. You can still get at these things by adding them to the method signatures that need them, you just can't easily do this at a field level thing.

The other downside to this approach is that all resources become effectively singletons. Not a big deal if your resources are simple objects that simply service requests, a big deal if your resources are storing any sort of state on them.



来源:https://stackoverflow.com/questions/31277675/is-it-possible-to-use-dagger2-with-jersey-the-same-way-it-is-possible-with-guice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!