Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Kkkrish
Level 4

08-03-2017

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.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

09-03-2017

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. 

Answers (15)

Answers (15)

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

09-03-2017

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

This is the new way for annotations.

Avatar

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Kkkrish
Level 4

09-03-2017

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

Avatar

Avatar
Validate 10
Level 4
Var
Level 4

Likes

44 likes

Total Posts

113 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 25
View profile

Avatar
Validate 10
Level 4
Var
Level 4

Likes

44 likes

Total Posts

113 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 25
View profile
Var
Level 4

09-03-2017

Hi Kkkrish,

As Daniel mentioned this should work, i have used it in one of my POC learnings, have uploaded the code at my github for your reference.

@Reference(target = "(service.label=TESTCALL)")

~VAr

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

09-03-2017

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. 

Avatar

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Daniel_H__A__Li
Level 2

09-03-2017

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.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

09-03-2017

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. 

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

09-03-2017

Avatar

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Kkkrish
Level 4

09-03-2017

Daniel Henrique Alves Lima wrote...

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.

 

Thanks Daniel, providing running sample would be great help.

Regards,

Kk

Avatar

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Daniel_H__A__Li
Level 2

09-03-2017

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.

Avatar

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Kkkrish
Level 4

09-03-2017

Daniel Henrique Alves Lima wrote...

Hi, Kk. As I've said before, you are missing the attribute called "target" in the annotation. @Reference doesn't accept an attribute called "value" (the default one). You must use target = "your LDAP filter to selected a specific service component". It's very straigthforward... Regards, Daniel.

 

Hi Daniel,

This works, sorry to post back very late.

Regards,

Kkkrish

Avatar

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Daniel_H__A__Li
Level 2

09-03-2017

        Hi, Kk. As I've said before, you are missing the attribute called "target" in the annotation. @Reference doesn't accept an attribute called "value" (the default one). You must use target = "your LDAP filter to selected a specific service component". It's very straigthforward... Regards, Daniel.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

09-03-2017

In your use case - are you setting up multiple service configurations - as opposed to 1 service with 1 configuration. This is an interesting use case. We do not have any examples on this. 

I will go through this too and see if I get the same results. Maybe something needs to be updated. I will post back. 

Avatar

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Kkkrish
Level 4

09-03-2017

Feike Visser wrote...

Why are you not setting these properties on the @Component annotation?

 

Hi Feike Visser,

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

This above code snippet i am using in a servlet where i need to create a service reference that is being used to call for retrieving configuration data from OSGI FELIX Factory console, am referring https://cqdump.wordpress.com/2014/08/05/managing-multiple-instances-of-services-osgi-service-factori... this article to create multiple instances of services via OSGI Service Factory. where as with above code its giving compilation error. and without any parameter to @Reference annotation it is compiled.

Is there any way that can help me in achieving  " how to retrieve OSGI multi services data from Service factory " ?

 

Kk

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

09-03-2017

Why are you not setting these properties on the @Component annotation?

Avatar

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 2
Daniel_H__A__Li
Level 2

Likes

6 likes

Total Posts

24 posts

Correct Reply

1 solution
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Daniel_H__A__Li
Level 2

08-03-2017

Hi.

Have you tried

@Reference(target = "(service.label=TESTCALL)")

instead?

@Reference annotation

Regards,

Daniel.