找不到以下类型的上下文数据:java.ws.rs.container.ContainerRequest(Wildfly错误) [英] Unable to find contextual data of type: java.ws.rs.container.ContainerRequest (Wildfly error)
问题描述
我正在使用Wildfly 9.0.1.Final
I am using wildfly 9.0.1.Final
我正在部署一个REST应用程序,该应用程序的端点定义如下:
I am deploying a REST application which has an endpoint defined like this:
@GET
@Path("/view/products")
@Produces(MediaType.APPLICATION_JSON)
@CORSEnabled
@Protected
public String getConfiguredProducts(
@Context ContainerRequestContext request) {
if (request != null) {
Integer companyId = (Integer) request.getProperty("company");
if (companyId != null) {
//do stuff
}
}
// ... more staff
}
应用程序运行时,将注入上下文,即'request'为非null.
When the application runs, the context is injected, i.e. 'request' is non null.
当我尝试检索属性时,我得到了错误消息:
When I try though to retrieve the property I get back the error:
executing GET /complaints/view/products:
org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data
of type: javax.ws.rs.container.ContainerRequestContext
请注意,该应用程序在glassfish/jersey上运行没有问题,当我尝试将其移至wildfly/resteasy时出现了问题.
Please note that the application was running without problems on glassfish/jersey and the problem appeared when I tried to move it to wildfly/resteasy.
有什么想法吗?
推荐答案
我正在回答我自己的问题,因为至少根据此,RestEasy似乎不支持注入ContainerRequestContext.
I am answering my own question, since it seems that RestEasy does not support injection of a ContainerRequestContext, at least according to this
https://docs.jboss.org/resteasy /docs/1.1.GA/userguide/html_single/#_Context
@Context批注允许您注入以下实例 javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo, javax.ws.rs.core.Request,javax.servlet.HttpServletRequest, javax.servlet.HttpServletResponse,javax.servlet.ServletConfig, javax.servlet.ServletContext和javax.ws.rs.core.SecurityContext 对象.
The @Context annotation allows you to inject instances of javax.ws.rs.core.HttpHeaders, javax.ws.rs.core.UriInfo, javax.ws.rs.core.Request, javax.servlet.HttpServletRequest, javax.servlet.HttpServletResponse, javax.servlet.ServletConfig, javax.servlet.ServletContext, and javax.ws.rs.core.SecurityContext objects.
相反,我注入了javax.ws.rs.core.HttpHeaders,之前我已在其中添加了所需的所有信息.
I injected a javax.ws.rs.core.HttpHeaders instead, where I had previously added all the information I needed.
这篇关于找不到以下类型的上下文数据:java.ws.rs.container.ContainerRequest(Wildfly错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!