Cannot inject HttpServletRequest in ContainerRequestFilter via @Context jersey2.x and weblogic 12.1.3

后端 未结 2 1160
名媛妹妹
名媛妹妹 2021-02-20 17:38

I was not able to inject HttpServletRequest in ContainerRequestFilter via @Context in Jersey 2.22.1 using weblogic 12.1.3. I researched several places that this issue exists and

2条回答
  •  深忆病人
    2021-02-20 17:57

    As an alternative to typically preferred injection by @Context, @Inject, or @Autowire, you can inject HttpServletRequest into a request-scoped bean using Spring's static method:

    HttpServletRequest request= 
    ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
    

    Note that this approach is not ideal, because static methods make your code harder to test and make your code more rigid.

提交回复
热议问题