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

后端 未结 2 1223
名媛妹妹
名媛妹妹 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.

    0 讨论(0)
  • 2021-02-20 18:08

    It seems this is a bug with Weblogic 12.1.3. I tried upgrading to Weblogic 12.2.1 and injecting HttpServletRequest using @Context works correctly even inside ContainerRequestFilter.

    0 讨论(0)
提交回复
热议问题