无法找到类型的上下文数据: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
我正在部署一个 REST 应用程序,它的端点定义如下:
@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'是非空的。
当我尝试检索 属性 时,我得到了错误:
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 时出现问题。
有什么想法吗?
我正在回答我自己的问题,因为 RestEasy 似乎不支持注入 ContainerRequestContext,至少根据这个
https://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html_single/#_Context
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,我之前在其中添加了我需要的所有信息。
我也有这个错误
RESTEASY003880: Unable to find contextual data of type: javax.ws.rs.core.HttpHeaders
这是由于在另一个线程中访问 headers 造成的。
希望答案对谷歌搜索问题有所帮助。
在我的例子中,它只是一个无效的 Content-Type header。错误肯定是误导。
我正在使用 wildfly 9.0.1.Final
我正在部署一个 REST 应用程序,它的端点定义如下:
@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'是非空的。
当我尝试检索 属性 时,我得到了错误:
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 时出现问题。
有什么想法吗?
我正在回答我自己的问题,因为 RestEasy 似乎不支持注入 ContainerRequestContext,至少根据这个
https://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html_single/#_Context
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,我之前在其中添加了我需要的所有信息。
我也有这个错误
RESTEASY003880: Unable to find contextual data of type: javax.ws.rs.core.HttpHeaders
这是由于在另一个线程中访问 headers 造成的。
希望答案对谷歌搜索问题有所帮助。
在我的例子中,它只是一个无效的 Content-Type header。错误肯定是误导。