The attribute policyOption is undefined for the annotation type Reference | Community
Skip to main content
Level 3
August 21, 2018
Solved

The attribute policyOption is undefined for the annotation type Reference

  • August 21, 2018
  • 12 replies
  • 4265 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

12 replies

smacdonald2008
Level 10
August 21, 2018

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... 

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
August 21, 2018
smacdonald2008
Level 10
August 21, 2018

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

smacdonald2008
Level 10
August 21, 2018

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 Sling 

Level 3
September 4, 2018

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

arunpatidar
Community Advisor
Community Advisor
September 4, 2018

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
Level 3
September 4, 2018

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

Thanks,

Vijay

arunpatidar
Community Advisor
Community Advisor
September 4, 2018

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
Level 3
September 4, 2018

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

Level 3
September 4, 2018

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?

Thanks,

vijay