Highlighted

OSGI component - unsatisfied Reference, No service bound issue in AEM 6.4

sivas61374651

05-09-2018

Hi All,

I have an OSGI component and inside that I have used @Reference(policyOption = ReferencePolicyOption.GREEDY) for the below interfaces,

protected HybrisConnection connection;

protected HybrisFactory hybrisFactory;

Once I install the bundle in AEM I'm getting unsatisfied (Reference) error for HybrisFactory (No service bound). The same @Reference I have used for HybrisConnection and its satisfied. For reference I have provide the screen shot. can anyone help me to resolve this?

1564570_pastedImage_1.png

The generated XML file is below,

<?xml version="1.0" encoding="UTF-8"?>

<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="soa.sample.aem.core.commerce.hybris.importer.DefaultHybrisImporter" activate="activate" deactivate="deactivate">

  <implementation class="soa.sample.aem.core.commerce.hybris.importer.DefaultHybrisImporter"/>

  <service>

    <provide interface="soa.sample.aem.core.commerce.hybris.importer.DefaultHybrisImporter"/>

    <provide interface="soa.sample.aem.core.commerce.hybris.importer.HybrisImporter"/>

  </service>

  <reference name="DeviceProductTransformer" interface="soa.sample.aem.core.commerce.hybris.importer.transformer.DeviceProductTransformer" bind="bindDeviceProductTransformer" unbind="unbindDeviceProductTransformer"/>

  <reference name="HybrisConnection" interface="soa.sample.aem.core.commerce.hybris.connection.HybrisConnection" bind="bindHybrisConnection" unbind="unbindHybrisConnection" policy-option="greedy"/>

  <reference name="ImportHandler" interface="soa.sample.aem.core.commerce.hybris.importer.ImportHandler" bind="bindImportHandler" unbind="unbindImportHandler" policy-option="greedy"/>

  <reference name="Replicator" interface="com.day.cq.replication.Replicator" bind="bindReplicator" unbind="unbindReplicator"/>

  <reference name="ServiceAddOnTransformer" interface="soa.sample.aem.core.commerce.hybris.importer.transformer.ServiceAddOnTransformer" bind="bindServiceAddOnTransformer" unbind="unbindServiceAddOnTransformer"/>

  <reference name="ServicePlanTransformer" interface="soa.sample.aem.core.commerce.hybris.importer.transformer.ServicePlanTransformer" bind="bindServicePlanTransformer" unbind="unbindServicePlanTransformer"/>

  <reference name="HybrisFactory" interface="soa.sample.aem.core.commerce.hybris.api.HybrisFactory" bind="bindHybrisFactory" unbind="unbindHybrisFactory" policy-option="greedy"/>

  <property name="getConnectionThreadPoolSize" type="Integer" value="2"/>

  <property name="hybris.import.products.path" type="String" value="/etc/commerce/products"/>

  <property name="hybris.import.product.asset.removal.enabled" type="String" value=" true"/>

  <property name="getProductsPath" type="String" value="/etc/commerce/products"/>

  <property name="hybris.import.product.removal.enabled" type="String" value="true"/>

  <property name="getExportFields" type="String" value="DEFAULT"/>

  <property name="hybris.import.export.fields" type="String" value="DEFAULT"/>

  <property name="sample.hybris.connection.threadpoolsize" type="String" value="2"/>

  <property name="hybris.import.pagesize" type="String" value="2147483647"/>

  <property name="getPageSize" type="Integer" value="2147483647"/>

  <property name="getProductRemovalEnabled" type="Boolean" value="true"/>

  <property name="getProductAssetRemovalEnabled" type="Boolean" value="true"/>

  <property name="commerceProvider" type="String" value="hybris"/>

</scr:component>

Sample piece of code:

  protected HybrisConnection connection;

  protected HybrisFactory hybrisFactory;

 

 

  @Reference(policyOption = ReferencePolicyOption.GREEDY) 

  public void bindHybrisConnection(HybrisConnection connection) {

    this.connection = connection;

  }

  public void unbindHybrisConnection(HybrisConnection connection) {

    this.connection = connection;

  }

 

  @Reference(policyOption = ReferencePolicyOption.GREEDY) 

  public void bindHybrisFactory(HybrisFactory hybrisFactory) {

    this.hybrisFactory = hybrisFactory;

  }

  public void unbindHybrisFactory(HybrisFactory hybrisFactory) {

    this.hybrisFactory = hybrisFactory;

  }

Feike Vissersmacdonald2008dgordon86navneetjainArun PatidarRima MittalRatna Kumarvjharry0123ronnyfmvitis90edubey

Thanks,

Vijay

Replies

Highlighted

smacdonald2008

05-09-2018

Are you following an online doc - if so please point community to it.

An unsatisfied Reference typically means that there is no target service available in the service registry. Therefore your component is not satisfied.

Highlighted

sivas61374651

05-09-2018

Hi Scott,

I have used like this below and now the component is active. But not sure is it a correct way to activate the component.

  @Reference(policyOption = ReferencePolicyOption.GREEDY, cardinality =

      ReferenceCardinality.OPTIONAL)

  public void bindHybrisFactory(HybrisFactory hybrisFactory) {

    this.hybrisFactory = hybrisFactory;

  }

  public void unbindHybrisFactory(HybrisFactory hybrisFactory) {

    this.hybrisFactory = hybrisFactory;

  }

Got the below input from this link,https://osgi.org/specification/osgi.cmpn/7.0.0/service.component.html  . Seems I should use 0..1​? am I right?

1564845_pastedImage_1.png

Thanks,

Vijay

Highlighted

smacdonald2008

05-09-2018

Looks like you are trying to use dependency injection in a bind method following that doc.

To use dependency injection, there is no need to place the @Reference within any specific method in Java. You can place @Refenence in a a Java class that uses @Component and then use that object in methods. See this article where we use this annotation.

@Component

public class EmployeeImpl implements EmployeeInter {

   

    /** Default log. */

    protected final Logger log = LoggerFactory.getLogger(this.getClass());

           

    private Session session;

               

    //Inject a Sling ResourceResolverFactory

    @Reference

    private ResourceResolverFactory resolverFactory;

    See -- Adobe Experience Manager Help | Querying Adobe Experience Manager 6.4 JCR data

This is how you can use any of the Services within AEM. If @Reference does not work - then the service is not available within AEM.