You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jason Chaffee <jc...@ebates.com> on 2010/06/15 21:39:01 UTC

Problems with inject Context into fields

I am trying to inject UriInfo into a field so that I don't have to
inject it into every method.  This works correctly when I deploy the app
as a webapp, but when I try to test my services using
JAXRSServerFactoryBean it doesn't get injected and I get a NPE.
However, it will get injected if I change service to inject into each
method.  

 

Any ideas what might be going wrong here?

 

Here is the code snippet:

 

        final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

        sf.setResourceClasses(MyService.class);

        sf.getInInterceptors().add(new LoggingInInterceptor());

        sf.getOutInterceptors().add(new LoggingOutInterceptor());

 

        sf.setResourceProvider(MyService.class,

            new SingletonResourceProvider(ctx.getBean("myService")));

        sf.setAddress(BASE_URI);

 

        sf.create();

 

and I have the folliwing field in MyService:

 

@Context UriInfo uriInfo;

 

Jason


Re: Problems with inject Context into fields

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Sorry for a late reply - I've finally managed to do a quick test this
evening and I had no problems with
UriInfo injected into @Context annotated fields.

Can you provide more info please ? How does a (sample) spring context look
like ?
cheers, Sergey


On Tue, Jun 15, 2010 at 8:39 PM, Jason Chaffee <jc...@ebates.com> wrote:

> I am trying to inject UriInfo into a field so that I don't have to
> inject it into every method.  This works correctly when I deploy the app
> as a webapp, but when I try to test my services using
> JAXRSServerFactoryBean it doesn't get injected and I get a NPE.
> However, it will get injected if I change service to inject into each
> method.
>
>
>
> Any ideas what might be going wrong here?
>
>
>
> Here is the code snippet:
>
>
>
>        final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>
>        sf.setResourceClasses(MyService.class);
>
>        sf.getInInterceptors().add(new LoggingInInterceptor());
>
>        sf.getOutInterceptors().add(new LoggingOutInterceptor());
>
>
>
>        sf.setResourceProvider(MyService.class,
>
>            new SingletonResourceProvider(ctx.getBean("myService")));
>
>        sf.setAddress(BASE_URI);
>
>
>
>        sf.create();
>
>
>
> and I have the folliwing field in MyService:
>
>
>
> @Context UriInfo uriInfo;
>
>
>
> Jason
>
>