简体   繁体   English

RESTEASY003880:找不到类型的上下文数据:javax.servlet.http.HttpServletRequest

[英]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.

相关问题 javax.servlet.http.HttpServletRequest 中的 HttpSession 如何工作 - How does HttpSession from javax.servlet.http.HttpServletRequest work 类型 javax.servlet.http.HttpServletRequest 不存在,gradle springfox-swagger2: 3.0 - Type javax.servlet.http.HttpServletRequest not present, with gradle springfox-swagger2: 3.0 使用JSF提交数据表值,并通过javax.servlet.http.HttpServletRequest访问它 - Submit datatable values with JSF and access it through javax.servlet.http.HttpServletRequest 为什么spring-boot-3会报javax.servlet.http.HttpServletRequest ClassNotFoundException - Why does spring-boot-3 give javax.servlet.http.HttpServletRequest ClassNotFoundException HTTP状态500-java.lang.ClassCastException:rest.rest页面无法转换为javax.servlet.http.HttpServletRequest - HTTP Status 500 - java.lang.ClassCastException: rest.rest Page cannot be cast to javax.servlet.http.HttpServletRequest 无法找到类型的上下文数据:io.vertx.core.http.HttpServerRequesta - Unable to find contextual data of type: io.vertx.core.http.HttpServerRequesta java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.startAsync - java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.startAsync java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.getPart - java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getPart java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.getParts() - java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getParts() @Controller导致java.lang.NoClassDefFoundError:javax / servlet / http / HttpServletRequest - @Controller causing java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM