从Guice ServletModule安装自定义Jersey ViewProcessor [英] Install custom Jersey ViewProcessor from Guice ServletModule
问题描述
我正在使用 jersey-guice 使用一堆Guice(Servlet)模块来设置我的Jersey 1的所有资源.
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.
我如何告诉Jersey在需要ViewProcessor
的情况下何时获取Guice创建的CustomViewProcessor
实例??我想在我的Guice Module
s'
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 Module
s' configure
methods.
推荐答案
我发现这很简单:只需创建该CustomViewProcessor
类,然后用
I found out that this is rather easy: Just create that CustomViewProcessor
class and annotate it with @Provider
. By bind
ing it with Guice (and having jersey-guice installed), your CustomViewProcessor
will be instantiated and used in the right places.
CustomViewProcessor
类可以使用所需的所有@Inject
ed字段,例如配置对象.
The CustomViewProcessor
class can use all the @Inject
ed fields that you wish, like configuration objects.
这篇关于从Guice ServletModule安装自定义Jersey ViewProcessor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!