Skip to main content
Level 4
Mar 9, 2017 5:18 AM UTC
Solved

@Reference(“(service.label=TESTCALL)”) Felix SCR annotation error

am trying to implement an OSGI service which can serve me as ConfigurationFactory the service implementation has just two properties as shown below.

@Property(value="this is service variable property value") static final String MY_SERVICE_VARIABLE = "service.variable"; @Property(description="Label for this MyService") private static final String MY_SERVICE_LABEL = "service.label";

and am retrieving this service configuration data from an OSGI servlet where i am trying to call this service by below code which compiles fine and retrieves data randomly from the multiple service configuration.

@Reference MyService myservice;


But when i wanted to get each configuration data by using the service.label and am calling the service by using below code snippet in my OSGI servlet, while compiling am facing the below Error.

@Reference("(service.label=TESTCALL)") MyService myservice;


cannot find symbol [ERROR] symbol: method value() [ERROR] location: @interface org.apache.felix.scr.annotations.Reference.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Mar 9, 2017 8:03 PM UTC

Daniel is correct - i went through this and this works: 

public class SimpleServlet extends org.apache.sling.api.servlets.SlingAllMethodsServlet {
     private static final long serialVersionUID = 2598426539166789515L;
        
     @Reference(target = "(mailservice.label=InternetA)")
     MailService mailService;    

We are turning this all into a HELPX Article so all the steps are included. 

16 replies

smacdonald2008
Level 10
Mar 9, 2017 9:45 PM UTC
smacdonald2008
Level 10
Mar 9, 2017 9:55 PM UTC

I have emailed you all the code so you can see it while the article (that uses the code that works  perfectly fine) is written. 

Translate
Daniel_H__A__Li
Level 2
Mar 9, 2017 10:43 PM UTC
No problem, kk. I've done something similar before. It's also possible to dynamically set the target property (making the value used as a LDAP filter configurable), but I'm far away from my computer to send you a running sample. Regards, Daniel.
Translate
KkkrishAuthor
Level 4
Mar 9, 2017 11:07 PM UTC

smacdonald2008 wrote...

I have emailed you all the code so you can see it while the article (that uses the code that works  perfectly fine) is written. 

 

Thanks Scott, It really helps.

Regards,

Kkkrish

Translate
smacdonald2008
Level 10
Mar 9, 2017 11:22 PM UTC

We will have complete article and video out next week - thank you for bringing this Doc Gap to our attention. This is how a great community works! Most of the HELPX content were driven from threads like this. 

I was able to get both configurable services working based on my posted value to the servlet. 

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
Mar 10, 2017 7:27 AM UTC

For those new examples can we use the annotations from org.osgi.service.component.annotations?

This is the new way for annotations.

Translate