【问题标题】:OSGi Declarative Services and Config AdminOSGi 声明式服务和配置管理
【发布时间】:2012-05-30 11:30:16
【问题描述】:

我正在编写包含声明性服务用法的捆绑包。对于配置,我在 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);

在组件中我有:

// ...

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

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

【问题讨论】:

  • 仅供参考,您可能希望为您的激活/停用/修改操作使用 (映射属性)签名,以避免在您的代码中包含 OSGi API。

标签: configuration osgi declarative-services


【解决方案1】:

问题出在 Pax Runner 中,每次重新启动(清理)都会删除 Config Admin 包的数据文件夹。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 2013-10-09
    相关资源
    最近更新 更多