我有一个OSGi转换器组件,它是通过吊索实例化的。在我的OSGi组件中,我有以下注释:
@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的属性
@Property(label = "CDN Url prefix", description = "CDN URL prefix", value = "")
private static final String CDN_URL_PREFIX = "cdn_url_prefix";现在,我可以在felix控制台中使用"+“符号为这个类提供多个配置。如果我有"N“数量的配置,sling将实例化我的StaticLinkRewriter类的N个对象。
问题:如何获得实例化对象的适当配置?我的意思是,当吊带实例化对象时,如何获得对象实例化的配置?
发布于 2015-09-14 20:36:32
我认为这个组件不是由Sling实例化的,而是通过声明性服务来实例化的。
如果实现activate方法,则可以获得配置。例如:
@Activate
void activate(ComponentContext ctx) {
Dictionary configuration = ctx.getProperties();
// use your configuration
}有关更多信息,请参见OSGi简编规范的112个声明性服务规范一章。
https://stackoverflow.com/questions/32566571
复制相似问题