Injection of HttpServletRequest

后端 未结 2 1960
鱼传尺愫
鱼传尺愫 2020-12-17 16:56

I am using ejb 3 and trying to @Inject HttpServletRequest, but while deploying I occur exception.

Code:

@Inject private HttpServletRequest httpReques         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 17:43

    If your dependent is a JAX-RS (Restful) class then note the answer above. On the other hand, if you've got a more complex arrangement of dependency injection the question is certainly valid.

    This capability has been added to the CDI 1.1 specification (JSR-346) which in turn has been added to the new Java EE 7 specification. In other words, the newest class of Java Enterprise Application servers will be able to handle this.

    In the meantime, if you need to be able to manage some request scopes dependencies that in term need access to the actual HttpServletRequest information, you can use your approach and use the JBoss Solder tool. (Don't panic if the web site looks defunct, the fact of the matter is the work got shifted to the official CDI 1.1 spec implementation—i.e. "Weld 2"—so they aren't working on solder any more. But it's still perfectly suitable for CDI 1.0.)

    The maven dependencies would be

    
      org.jboss.solder
      solder-api
      3.2.0.Final
      jar
      compile
    
    
      org.jboss.solder
      solder-impl
      3.2.0.Final
      jar
      compile
    
    

提交回复
热议问题