dependency injection - EJB JAX-RS @Context HttpServletRequest NullPointerException - Why? -


consider following service:

@path("/") @stateless public class somethingservice {      @context     final httpservletrequest request      @post     @path("post/something/")     @produces("application/json; charset=utf-8")     public string addsomething(@formparam("something") final string something) {         // access request methods results in nullpointerexception     } } 

i nullpointerexception when method executes, though in debugging perspective noticed request wasn't null rather instance of org.apache.openejb.rest.threadlocalhttpservletrequest. when move @context injection method parameter level, works fine:

public string addsomething(@formparam("something") final string something,     @context final httpservletrequest request) { ... } 

what reason this? far remember used work before made service ejb (which did make injection of daos using @ejb or @inject possible). jax-rs create instance of such service every request , hence able inject via class level @context? ejb prevent creating instance , filling in proxy objects before jax-rs can anything?

necroing old question -

when turned stateless, turned singleton model, injecting fields no longer thread safe. same thing happens when turn jax-rs service spring bean. safer way workaround mentioned, , inject methods parameters.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -