OSGi声明服务和配置管理员

时间:2012-05-30 11:30:17

标签: configuration osgi declarative-services

我正在使用声明性服务用法编写捆绑包。对于配置,我在DS声明中使用属性。 Config Admin可以正常更改这些道具,但它们不会保留。容器重启后,组件具有默认值。

我正在使用这样的配置管理员:

Configuration c = configurationAdmin.getConfiguration(UserAgent.SERVICE_PID, null);
System.out.println(c.getProperties()); // every time is null!
Dictionary props = new Hashtable();
props.put(UserAgent.PROPERTY_PORT, 5555);
c.update(props);

在组件I中:

// ...

@Modified
public void updated(ComponentContext context) {
    config = context.getProperties();
    init();
}

@Activate
protected void activate(ComponentContext context) {
    config = context.getProperties();
    init();
}
//...

我正在使用Felix,属性文件存储在缓存中

service.bundleLocation="file:bundles/cz.b2m.osgi.phonus.core_1.0.0.SNAPSHOT.jar"
service.pid="cz.b2m.osgi.phonus.sip"
port=I"5555"

但重启后没有加载。我做错了什么?感谢所有提示。

1 个答案:

答案 0 :(得分:1)

Pax Runner出现问题,每次重启(清理)都会删除Config Admin bundle的数据文件夹。

要确保Pax Runner不会清除数据,您可以使用--usePersistedState=true标记。