문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top