【问题标题】:How to configure declarative service in CQ5如何在 CQ5 中配置声明式服务
【发布时间】:2012-11-28 12:38:24
【问题描述】:

如何在 CQ5 中通过 OSGI 控制台配置声明式服务。 我能够构建示例服务,捆绑代码我得到 jar 并通过 bundle 安装 OSGI 控制台

【问题讨论】:

标签: adobe osgi aem apache-felix


【解决方案1】:

第一步是定义您的服务具有配置参数。你可能有这样的事情:

package com.sample.osgi;

import java.util.Map;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;

@Component(label = "Service Label", description = "Service Description", metatype = true, immediate = true)
public class ConfigurableService {

    @Property(value="default value", label = "Sample Parameter", description = "Example of a component parameter")  
    private static final String SAMPLE_PARAM_NAME = "param.one"; 

    @Activate
    protected void activate(final Map<String, Object> props) {
        this.update(props);
    }

    @Modified
    protected void update(final Map<String, Object> props) {        
        System.out.println(props.get(SAMPLE_PARAM_NAME));
    }

}

获得服务后,您应该使用 maven 生成 scr 描述符,创建捆绑包并将其部署到本地服务器。这在this page 上有所描述。

部署后,您应该能够在服务器上的 felix 控制台中看到您的服务。例如:

http://localhost:4502/system/console/configMgr/com.sample.osgi.ConfigurableService

由于我们添加了带有 @Modified 注解的更新方法,您的组件将接收到配置值的更新,因为它们是通过调用该方法进行的。

您可以找到有关 SCR 注释 on the felix site 的更多信息

【讨论】:

    猜你喜欢
    • 2014-12-10
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 2012-04-27
    • 2018-05-20
    • 1970-01-01
    相关资源
    最近更新 更多