Expand my Community achievements bar.

SOLVED

The attribute policyOption is undefined for the annotation type Reference

Avatar

Level 3

Hi

can anyone help on this below issue,

We are replacing felix annotations with OSGI DS annotations. We have come across with a challenge please find below

Felix annotation :

  @Reference(policyOption = ReferencePolicyOption.GREEDY)

  protected UserConnector userConnector;

 

OSGI Annotation I tried :

  protected UserConnector userConnector;

 

  @Reference(policyOption = ReferencePolicyOption.GREEDY)

  public void bindUserConnector(UserConnector userConnector) {

    this.userConnector = userConnector;

  }

  public void unbindUserConnector(UserConnector userConnector) {

    this.userConnector = userConnector;

  }

 

But there is an error in eclipse where “The attribute policyOption is undefined for the annotation type Reference”.

Can you please tell me whether policyOption is deprecated in OSGi annotations.

Please let me know how to use policyOption = ReferencePolicyOption.Greedy in @Reference OSGI annotation.

Much Appreciated in advance.

Arun Patidar

Feike Visser

smacdonald2008

Thanks

Vijay

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
12 Replies

Avatar

Level 10

The syntax is not a 1-1 match between felix and DS annotations.

Here is the reference for a DS annotation that will help...

https://osgi.org/javadoc/r4v43/cmpn/org/osgi/service/component/annotations/Reference.html

You can see the applicable values for policyOption.

Hope this helps... 

Avatar

Correct answer by
Community Advisor

Avatar

Level 10

Nice response Arun - great to see that you were able to build this.

Avatar

Level 10

On a related note - for those reading this thread and wanting to know more about DS Annotations - read this from Nate Yolles - a great article:

Official OSGi Declarative Services Annotations in AEM - Adobe Experience Manager | AEM/CQ | Apache S... 

Avatar

Level 3

Hi Arun,

It's not working for me @Reference(policyOption = ReferencePolicyOption.GREEDY) and I'm getting this error in eclipse where “The attribute policyOption is undefined for the annotation type Reference”. if I use the below dependency in my pom.xml,

<dependency>

<groupId>biz.aQute</groupId>

<artifactId>bndlib</artifactId>

<version>1.50.0</version>

<scope>provided</scope>

</dependency>

Eclipse allow me to use GREEDY  if I use the below dependency and i Just changed the version and build is success. But when I install the bundle, in /system/console/components/ I'm getting unsatisfied (reference) error and it is not active. The version number I got it from MAVEN central repo. FYI

<dependency>

<groupId>biz.aQute</groupId>

<artifactId>bndlib</artifactId>

<version>2.0.0.20130123-133441</version>

<scope>provided</scope>

</dependency>

Can you help me to resolve this? Also I could see in your earlier post that you were able to use GREEDY, what is the exact dependency & import you have used? can you share that.

Thanks,

Vijay

Avatar

Community Advisor

Hi,

I am using osgi annotations

import org.osgi.service.component.annotations.Reference;

import org.osgi.service.component.annotations.ReferencePolicyOption;

<dependency>

  <groupId>org.osgi</groupId>

  <artifactId>osgi.cmpn</artifactId>

  <version>6.0.0</version>

  <scope>provided</scope>

</dependency>



Arun Patidar

Avatar

Level 3

Using the same Imports & dependency Arun but doesn't work . any clue like if I did anyother mistake?

1563913_pastedImage_1.png

Thanks,

Vijay

Avatar

Community Advisor

Hi,

Do you have multiple imports ?

Check below osgi Annotation

https://osgi.org/javadoc/r6/residential/org/osgi/service/component/annotations/Reference.html

In Eclipse, can you click on Policy, PolicyOption or  ReferencePolicyOption and press F4 to check from where reference is used.You can see the jar name in status bar

@Reference(policyOption=ReferencePolicyOption.GREEDY)



Arun Patidar

Avatar

Level 3

Hi Arun,

As you said I found at the issue with my jar. @Reference is pointing out out to this JAR maven\repository\biz\aQute\bndlib\1.50.0\bndlib-1.50.0.jar and if I see the Reference interface inside the jar policyOption is not available and that's why I'm unable to use policyOption.

Now I should pointing to this maven\repository\org\osgi\osgi.cmpn\6.0.0.jar. Inside the jar I'm having Reference interface where I can see the policyOption(). how can I change the reference now? can you guide me on the same.

Thanks.,

Vijay

Avatar

Level 3

Hi Arun,

Fixed the issue. Changed the order of dependencies and now its pointing to osgi.cmpn. but still I'm getting unsatisfied reference issue.Any Idea?

1564037_pastedImage_0.png

Thanks,

vijay

Avatar

Community Advisor

Hi,

For my test service, it is in satisfied state.

your issue could be due to dependancy code or something but not sure.

Screen Shot 2018-09-04 at 4.23.46 PM.png



Arun Patidar

Avatar

Level 3

Hi Arun,

Do you have any idea about No services bound? If you see my above screenshot for the unsatisfied service It shows No Services bound.

Also I have used policyOption:Greedy for three references Where it is satisfied for HybrisConnection and unsatisfied for HybrisFactory & ImportHandler.

Thanks,

Vijay