Hi Dario,

It is a mistake to put @Reference on both the bind and unbind methods. Also if 
you’re using Declarative Services with a static policy then it isn’t necessary 
to have an unbind method at all.

The next thing to check is, are you using a tool which processes the 
Declarative Services annotations when building the bundle? Does the bundle have 
a Service-Component header and a matching XML file? I’m guessing that you 
probably do as you refer to the reference not being set, but it’s still worth 
checking!

Regards,

Tim


> On 2 Feb 2017, at 16:01, Dario Amiri <[email protected]> wrote:
> 
> Hello all, I'm hoping you can help me with an issue that is baffling me.
> 
> In one bundle I'm exposing a service through blueprint
> 
>     <service id="dataSvc"
>         interface="org.example.data.Data"
>         ref="data">
>     </service>
> 
> In another bundle I'm trying to inject that service with annotations
> 
>     @Reference(unbind = "unsetData")
>     public void setData(final Data data) {
>         this.data = data;
>     }
> 
>     @Reference
>     public void unsetData(final Data data) {
>         this.data = null;
>     }
> 
> Unfortunately, this is not working. The reference always ends up being 
> null. I have other services that I am injecting into the same class 
> which are exposed by yet other bundles using annotations and declarative 
> services which work fine. Also I can clearly see all the services if I 
> run either the "ls" or "services" command in Karaf. Can anyone tell me 
> if I am doing something wrong or help me troubleshoot this issue?
> 
> Regards,
> 
> D
> 
> 

Reply via email to