我可以使用 @Context 注释注入哪些对象? [英] What objects can I inject using the @Context annotation?

查看:35
本文介绍了我可以使用 @Context 注释注入哪些对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JAX-RS 的新手,我想了解 @Context 注释应该如何工作.

I'm new to JAX-RS and I'm trying to understand how the @Context annotation is supposed to work.

javadoc 处是六个类的列表(ApplicationUriInfoRequestHttpHeadersSecurityContext>、提供者).但是我在网上找到了将 this 注释用于其他类型的代码,例如:

At the javadoc there is a list of six classes (Application, UriInfo, Request, HttpHeaders, SecurityContext, Providers). However I find code on the web that use the this annotation with other types, for example:

@GET
public String something(@Context HttpServletRequest req) {

}

是否有可与此注释一起使用的受支持类型列表?此列表在标准实施之间是否会发生变化?

Is there a list of supported types that can be used with this annotations? Does this list change between implementation of the standard?

我目前正在试验 Jersey,但我担心我会编写无法移植到其他 JAX-RS 实现的代码.

I'm currently experimenting with Jersey and I'm worried that I'll write code that cannot be ported to other JAX-RS implementation.

推荐答案

引人入胜的 JAX-RS 规范 定义了您可以通过 @Context 注入的所有标准类型.

The riveting JAX-RS specification defines all the standard types you can inject via @Context.

但如果我是你,我只会查阅你选择的提供商的具体文档,看看有什么可用的.

But if I were you, I would just consult the specific documentation of your chosen provider to see what is available.

例如,RESTEasy 提供了这些值 通过 @Context.同时,Jersey 提供这些.显然,由于标准上下文值,会有重叠.

For example, RESTEasy provides these values via @Context. Meanwhile, Jersey provides these. Obviously there will be overlap because of the standard context values.

这篇关于我可以使用 @Context 注释注入哪些对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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