我可以使用@Context注释注入哪些对象? [英] What objects can I inject using the @Context annotation?
问题描述
我是JAX-RS的新手,我正在尝试理解 @Context
注释应该如何工作。
I'm new to JAX-RS and I'm trying to understand how the @Context
annotation is supposed to work.
在 javadoc 有六个类的列表(应用程序
, UriInfo
,请求
, HttpHeaders
, SecurityContext
,提供商
) 。但是,我在Web上找到了使用此注释与其他类型的代码,例如:
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 规范定义了可以通过<$ c注入的所有标准类型$ c> @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
。同时,泽西岛提供这些。由于标准的上下文值,显然会有重叠。
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屋!