How can I read factory configurations for my OSGI instance

◇◆丶佛笑我妖孽 提交于 2019-12-12 02:44:00

问题


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

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

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 ?


回答1:


I think this component is not instantiated by Sling but by Declarative Services.

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
}

For more information, see the 112 Declarative Services Specification chapter of OSGi Compendium specification.



来源:https://stackoverflow.com/questions/32566571/how-can-i-read-factory-configurations-for-my-osgi-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!