【发布时间】: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