I am using CXF + Spring.

I'm having a lot of problems getting confused by the two separate injection 
systems. I have a resource class created by Spring (A), and it requires a 
dependency (Dep). Normally I can have Dep injected into Res with @AutoWired, 
and this works fine. But I want the Dep to have a reference to UriInfo. Ideally 
I want this:

@Path("/")
class A {
  @Autowired
  public A(Dep dep) { /* save dep */ }

  @GET
  public String get() { return ""; }
}

class Dep {
  @Autowired
  public Dep(UriInfo uriInfo) { /* ... */ }
}

I tried making a ContextResolver<Dep> and making a field @Context Dep dep, and 
this gave an error that Dep is not an interface. So I created an IDep and 
ContextResolver<IDep> and it is set to a Proxy but that proxy always throws NPE 
in Method.invoke (not my code). I also tried @Context on a setter. It seems 
that I cannot add arbitrary things to be injected by JAX-RS, and I can't get 
access to the JAX-RS resources in Spring injection. So I have no solution to 
this problem. My current "workaround" is:

class A {
@Context public setUriInfo(UriInfo uriInfo) { this.dep = new Dep(uriInfo); }
}

However, this defeats the use of dependency injection and would get very hard 
to work with if/when Dep needs any other things.

Jason Winnebeck

----------------------------------------------------------------------
This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.

Reply via email to