@Reference("(service.label=TESTCALL)") Felix SCR注解错误

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

我正在尝试实现一个可以作为 ConfigurationFactory 服务的 OSGI 服务,该服务实现只有两个属性,如下所示。

@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";

我正在从 OSGI servlet 中检索此服务配置数据,我试图通过以下代码调用此服务,该代码编译良好并从多个服务配置中随机检索数据。

@Reference
MyService myservice;

但是当我想通过使用 service.label 获取每个配置数据并在我的 OSGI servlet 中使用以下代码片段调用服务时,在编译时遇到以下错误。

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

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

您的服务很可能缺少 Service Factory 注释。类似于:

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

    } 

注意 configurationFactory=true 属性。这使该服务可以具有多个配置。

对 AEM 6.x 版本使用 @Reference(target = "(service.label=TESTCALL)"),应该可以编译。我已经在 gourivar github and the same POC example you can find at my aemvardhan.wordpress.com

上传了我之前使用过的示例 POC