I suppose you're using CDI and pax-cdi.
In such a case, injection in a bundle activator won't work.

2016-05-18 18:18 GMT+02:00 Frizz <[email protected]>:

> I have a OSGi service that I'd like to inject in one of my bundles.
> When I use @Inject it's always Null - and I don't understand why. Is it
> not possible to use @Inject in a BundleActivator?
>
> When I manually access the Service Registry (-> see start() method) it
> works fine.
>
> public class ClientActivator implements BundleActivator {
>
>     @Inject
>     IMyService service;
>
>     @Override
>     public void start(BundleContext context) throws Exception {
>         System.out.println(service); // -> Null
>
>         ServiceReference reference =
> context.getServiceReference(IMyService.class.getName());
>         IMyService service = (IMyService) context.getService(reference);
>         System.out.println(service); // -> not Null
>     }
> ...
> }
>



-- 
------------------------
Guillaume Nodet
------------------------
Red Hat, Open Source Integration

Email: [email protected]
Web: http://fusesource.com
Blog: http://gnodet.blogspot.com/

Reply via email to