The other thing that usually works is to put the @Resource on a setter, not 
the field:

WebServiceContext ctx;

@Resource
public void setWebServiceContext(WebServiceContext c)  {
    ctx = c;
}

When you do that, we can usually call the setter.   The problem with the aop 
proxy things is we have no access to the underlying fields.   Thus, we need a 
setter.

Dan


On Fri August 14 2009 4:08:48 am Nicola D'Elia wrote:
> thank you Daniel for your prompt and exhaustive anwer.
>
> Actually i had already tried importing META-INF/cxf/cxf-extension-*.xml,
> but that didn't help.
>
> Maybe i'll try instantiating the WebServiceContext directly....
> now i switched from spring aop proxies to aspectj compile time weaving: it
> works like a charm :)
>
>
>
> Nicola
>
> On Thu, Aug 13, 2009 at 4:43 PM, Daniel Kulp <[email protected]> wrote:
> > Couple possible ways to handle it:
> >
> > 1)  Add an import for "META-INF/cxf/cxf-extension-jaxws.xml"
> > That registers an additional injector for injecting the WebServiceContext
> > into
> > spring beans prior to them being proxied.     That works MOST of the
> > time, but
> > not all.
> >
> > 2) Don't @Resource it and just do:
> > WebServiceContext ctx
> >     = new org.apache.cxf.jaxws.context.WebServiceContextImpl();
> >
> > That's all that would be occuring when injected anyway.
> >
> > 3) In your method calls that need it, you can just do:
> > ctx = new org.apache.cxf.jaxws.context.WebServiceContextImpl();
> > as well.   Basically, the WebServiceContextImpl just wrappers a thread
> > local.
> >
> >
> > Dan
> >
> > On Thu August 13 2009 4:59:12 am Nicola D'Elia wrote:
> > > Hi to everyone,
> > > i have a problem injecting the web-service-context into a spring bean
> > > exposed as a web service through cxf.
> > >
> > > If the bean is a pojo everything works.
> > >
> > > When i enable Spring AOP, the bean becomes an AOP proxy and the
> > > resource does not get injected (is null).
> > >
> > > I tryed with JDK Dynamic Proxy and the ResourceInjector throws
> > > exception
> >
> > in
> >
> > > tests (both with field and setter injection).
> > >
> > > I switched to CGLIB proxy and everything works fine in tests, but when
> > > deployed in Jboss/Tomcat the context is null, no exception thrown.
> > >
> > >
> > > Are there known issues and patch/warkaround about the problem ?
> > >
> > > Or is there a way to get the web-service-context programmatically ?
> > >
> > >
> > > Thank you very much, any help appreciated.
> > >
> > >
> > > Nicola
> >
> > --
> > Daniel Kulp
> > [email protected]
> > http://www.dankulp.com/blog

-- 
Daniel Kulp
[email protected]
http://www.dankulp.com/blog

Reply via email to