title: osgi: Using ServiceFactories?
body: <p>I'm currently trying to get a simple bundle containing a Service Factory running.</p>
  
  <p>This is my factory class:</p>
  
  <pre><code>public class SvcFactory implements ServiceFactory&lt;ServiceB&gt; {
  
      @Override
      public ServiceB getService(Bundle bundle,
              ServiceRegistration&lt;ServiceB&gt; registration) {
  
          return new ServiceBImpl();
      }
  
      @Override
      public void ungetService(Bundle bundle, ServiceRegistration&lt;ServiceB&gt; registration,
              ServiceB service) {
  
      }
  
  }
  </code></pre>
  
  <p>This is my service that should be created by the factory:</p>
  
  <pre><code>public class ServiceBImpl implements ServiceB {
  
      private ServiceA svcA;
  
      public void setA(ServiceA a) {
          svcA = a;
      }
  
  }
  </code></pre>
  
  <p>And finally the OSGI-INF/component.xml </p>
  
  <pre><code>&lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="bundleb.internal.SvcFactory"&gt;
  
     &lt;implementation class="bundleb.internal.SvcFactory"/&gt;
  
    &lt;reference bind="setA" cardinality="1..1" interface="bundlea.ServiceA" name="ServiceA" policy="static"/&gt;
  
     &lt;service servicefactory="true"&gt;
        &lt;provide interface="bundleb.ServiceB"/&gt;
     &lt;/service&gt;
  &lt;/scr:component&gt;
  </code></pre>
  
  <p>If I run my test bundles (A, B and C) within equinox I'm getting the following error:</p>
  
  <pre><code>org.osgi.framework.ServiceException: org.eclipse.equinox.internal.ds.FactoryReg.getService() returned a service object that is not an instance of the service class bundleb.ServiceB
  </code></pre>
  
  <p>I can't find much information about using ServiceFeactories declared in a component definition on the internet. Even the book "OSGi and Equinox" didn't tell me much about using them.
  Could anyone please explain to me what I'm doing wrong?</p>