0

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.

krish
  • 469
  • 1
  • 15
  • 34

2 Answers2

0

Your service is most likely missing the Service Factory annotation. Something like:

    @Service
    @Component(
        metatype=true,label="my service", 
        description="sample my service implementation",
        configurationFactory=true)
        public class MyServiceImpl implements MyService { 

    } 

Note the configurationFactory=true attribute. This enables the service to have multiple configurations.

Imran Saeed
  • 3,414
  • 1
  • 16
  • 27
  • my service has the annotation included already, and it works when I use it as **@Reference MyService myservice;**, it fails compilation when I use as **@Reference("(service.label=TESTCALL)") MyService myservice;** because I want to retrieve the configuration data seperated(I.e. All configuration data which is of multiple services) – krish Mar 09 '17 at 09:43
  • Let me ask another way the same question, **how to retrieve the factory service multiple configurations data**.? Any code snippet helps. – krish Mar 09 '17 at 10:07
  • Your approach is fine and without looking at the code snippet (maybe if you can gist it?) I can't see any reason for compilation error. You can try the code snipper from https://cqdump.wordpress.com/2014/08/05/managing-multiple-instances-of-services-osgi-service-factories/ and see if it works as I just tried it locally and it compiles ok (haven't tested the binding but I guess that's not the issue here). – Imran Saeed Mar 09 '17 at 10:09
  • Yes have referred the same article and trying to achieve **@Reference(“(mailservice.label=INTERNET)”) MailService mailService;** for my service but without any parameters to @Reference annotation it compiles and works fine, if I add the parameter to it as shown above it fails. Will it be possible to share your local code as package? So that I can compare and may be it might help in debugging – krish Mar 09 '17 at 10:14
  • Any chance you are using 6.x as just tried it on 6.x and it doesn't work? I have compiled the sample on 5.6 (copy pasted from the site above) and it works. 6.x with new OSGi has a different way of doing this. – Imran Saeed Mar 09 '17 at 11:30
  • am using AEM6.2 version. – krish Mar 09 '17 at 23:31
0

use @Reference(target = "(service.label=TESTCALL)") for AEM 6.x versions, it should compile. I have uploaded the sample POC that i have used earlier at my gourivar github and the same POC example you can find at my aemvardhan.wordpress.com

VAr
  • 2,551
  • 1
  • 27
  • 40