如何读取OSGI实例的出厂配置 [英] How can I read factory configurations for my OSGI instance
问题描述
我有一个通过吊索实例化的OSGi变压器组件.在我的OSGi组件中,我具有以下注释:
I have a OSGi Transformer component which is instantiated by sling. In my OSGi component I have the following annotations :
@Component(configurationFactory = true, metatype = true, policy = ConfigurationPolicy.REQUIRE, label = "CDN Link Rewriter", description = "Rewrites links to all static files to use configurable CDN")
@Service(value = TransformerFactory.class)
public class StaticLinkTransformer implements Transformer,
TransformerFactory
我有一些属性,我将其注释为@Property
I have some properties which I have annotated as @Property
@Property(label = "CDN Url prefix", description = "CDN URL prefix", value = "")
private static final String CDN_URL_PREFIX = "cdn_url_prefix";
现在,我可以在felix控制台中使用"+"号为此类提供多种配置.如果我有"N"个配置,则吊索将实例化我的StaticLinkRewriter类的N个对象.
Now I am able to provide multiple configurations for this class using "+" sign in felix console. If I have "N" number of configurations, sling is instantiating N objects of my StaticLinkRewriter class.
问题:如何为实例化的对象获取正确的配置?我的意思是,在吊索实例化我的对象时,如何获得实例化对象的配置?
Question : How do I get the proper configurations for the object instantiated ? I mean, when sling instantiates my objects, how can i get the configurations for which the object was instantiated ?
推荐答案
我认为此组件不是由 Sling 实例化的,而是由 Declarative Services 实例化的.
I think this component is not instantiated by Sling but by Declarative Services.
如果实现activate方法,则可以获取配置.例如:
You can get the configuration if you implement the activate method. E.g.:
@Activate
void activate(ComponentContext ctx) {
Dictionary configuration = ctx.getProperties();
// use your configuration
}
有关更多信息,请参见OSGi汇编规范的 112声明式服务规范章节.
For more information, see the 112 Declarative Services Specification chapter of OSGi Compendium specification.
这篇关于如何读取OSGI实例的出厂配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!