我具有类似于下面的类:如何摆脱不存在于其相应配置(“service.pid”等)中的OSGi包的属性?
@Component(configurationPid = "foo.bar", configurationPolicy = ConfigurationPolicy.REQUIRE)
public class MyClass {
@Activate
public void activate(Map<String, Object> properties) throws Exception {
for (String property : properties.keySet()) {
if (!isValidProperty(property)) {
throw new IllegalArgumentException("Unknown property: " + property);
}
...
}
}
}
的properties
地图必须包含从相应的配置源特性(例如由用户提供的文件)。它也是,但它也包含一些并不存在的属性(service.pid
,felix.fileinstall.dir
等),所以我的程序被破坏了。我想以某种方式摆脱它们。
我试图使用ConfigurationAdmin.getConfiguration.getProperties
和蓝图cm-properties
,但是这给出了相同的效果。
我无法硬编码要排除的属性的名称,因为我不知道它们是什么。
是否有任何方法可以告诉OSGi运行时不要在我的地图中放置它们?
我正在使用ServiceMix的OSGi支持(本质上是Karaf,Felix和白羊座)。
这些属性是规范强制要求的,所以我不确定Felix如何'合法'摆脱它们 –