Hi Robert,

From the code snippet it looks as though you aren’t using the standard 
annotations (OPTIONAL_UNARY isn’t one of the enum values). If you want support 
for non-standard annotations then you’ll probably be best served by using the 
relevant mailing list for the community that provides the annotations.

If you were using the standard DS annotations then I would be telling you that 
what you’re doing is supported, but that you should be careful when using 
optional or multiple references with a static reluctant injection policy. The 
static reluctant policy rarely gives you the desired behaviour in these cases 
and usually results in your component having no reference even when there is a 
suitable service available.

Regards,

Tim

> On 21 Nov 2017, at 13:28, Robert Munteanu via osgi-dev 
> <osgi-dev@mail.osgi.org> wrote:
> 
> Hi,
> 
> I have an SCR component that references a service, with 0...1
> cardinality. That service is part of an optional import. The aim is
> that if the package is available at runtime, the reference is bound,
> otherwise not, but the component functions without it, e.g.
> 
> 
> @Component public class SomeComponent {
> 
> @Reference private FooService foo;
> 
> @Reference(cardinality = OPTIONAL_UNARY ) private BarService bar;
> 
> }
> 
> The result though is that the component bind method lookups fail, e.g.:
> 
> Failure loooking up method
> bindFoo(org.osgi.framework.ServiceReference) in class
> com.example.SomeComponent. Assuming no such method.
> (java.lang.NoClassDefFoundError: com/example/optional/BarService)
> 
> What's interesting is that the 'foo' reference is not part of an
> optional import, the class is visible and the reference is there.
> Obviously in this scenario the optional import for BarService is not
> satisfied and the class it not available.
> 
> I'm running org.apache.felix.scr from the latest OSGi-r7 folder -
> https://svn.apache.org/repos/asf/felix/trunk/osgi-r7/scr/ .
> 
> So my questions are:
> 
> 1. Is this scenario something that SCR can support?
> 2. If the answer above is no, what is the best way of achieving the
> result? Splitting the bundle is unfortunately quite tedious so I'd
> like to avoid that.
> 
> Thanks,
> 
> Robert
> 
> -- 
> http://robert.muntea.nu/
> _______________________________________________
> OSGi Developer Mail List
> osgi-dev@mail.osgi.org
> https://mail.osgi.org/mailman/listinfo/osgi-dev

_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to