从Guice ServletModule安装自定义Jersey ViewProcessor [英] Install custom Jersey ViewProcessor from Guice ServletModule

查看:132
本文介绍了从Guice ServletModule安装自定义Jersey ViewProcessor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 Modules' configure methods.

推荐答案

我发现这很简单:只需创建该CustomViewProcessor类,然后用

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.

CustomViewProcessor类可以使用所需的所有@Inject ed字段,例如配置对象.

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

这篇关于从Guice ServletModule安装自定义Jersey ViewProcessor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆