[英]RESTEASY003880: Unable to find contextual data of type: javax.servlet.http.HttpServletRequest
Hi when i am trying to open my applications' login page on browser , i am getting this exception.嗨,当我试图在浏览器上打开我的应用程序的登录页面时,我收到了这个异常。 PS : open jdk zulu 11 and wildfly 24 for deployment.
PS:打开jdk zulu 11和wildfly 24进行部署。
org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: Unable to find contextual data of type: javax.servlet.http.HttpServletRequest
at org.jboss.resteasy.resteasy-jaxrs@3.15.1.Final//org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:77)
at javax.servlet.api@2.0.0.Final//com.sun.proxy.$Proxy163.getSession(Unknown Source)
at deployment.demo.ear.rest.war//com.demoapp.demo.rest.resources.Myclass.init(Myclass.java:107)
Myclass.java我的类.java
import javax.ws.rs.core.Context;
import javax.servlet.http.HttpServletRequest;
@Path("")
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.WILDCARD})
public abstract class Myclass{
@Context
protected HttpServletRequest requestContext;
@PostConstruct
void init() {
HttpSession session = requestContext.getSession(); // exception at this line
try {
//some code here
} catch (Exception e) {
}
}
}
Please suggest.请建议。
In my experience the @Context
is set on a per method basis.以我的经验,
@Context
是基于每个方法设置的。 More like:更像:
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response myMethod(String someString, @Context HttpServletRequest request) {
In this way the HttpServletRequest
is set on a method basis, not a class basis.这样,
HttpServletRequest
是基于方法设置的,而不是基于类的。 I don't think you want it at the class level as if the class has many methods those methods shouldn't share the same HttpServletRequest
.我认为您不希望在类级别上使用它,就好像该类具有许多方法,这些方法不应共享相同的
HttpServletRequest
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.