Install custom Jersey ViewProcessor from Guice ServletModule

倖福魔咒の 提交于 2019-12-25 03:05:27

问题


I am using jersey-guice to set up all my Jersey 1 resources using a bunch of Guice (Servlet)Modules.

I have written a custom ViewProcessor (CustomViewProcessor) that relies on a configuration object, that I want to be injected into it using Guice. This CustomViewProcessor should be picked up and used by Jersey every time it needs one.

How do I tell Jersey to fetch a Guice-created CustomViewProcessor instance whenever it needs a ViewProcessor? I want to set all this up within my Guice Modules' configure methods.


回答1:


I found out that this is rather easy: Just create that CustomViewProcessor class and annotate it with @Provider. By binding it with Guice (and having jersey-guice installed), your CustomViewProcessor will be instantiated and used in the right places.

The CustomViewProcessor class can use all the @Injected fields that you wish, like configuration objects.



来源:https://stackoverflow.com/questions/22534429/install-custom-jersey-viewprocessor-from-guice-servletmodule

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