Is BarService part of that optional (implementation) bundle? I don’t  think 
that is supposed to work. It needs to be a import resolved from an always 
present (API) bundle.

Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
From: osgi-dev-boun...@mail.osgi.org <osgi-dev-boun...@mail.osgi.org> on behalf 
of Robert Munteanu via osgi-dev <osgi-dev@mail.osgi.org>
Sent: Tuesday, November 21, 2017 2:28:16 PM
To: OSGi Developer Mail List
Subject: [osgi-dev] Declarative services and optional imports

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