我正在编写带有声明性服务用法的包。对于配置,我在 DS 声明中使用属性。这些 Prop 通常可以由 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"
但是重启后没有加载。我做错了什么?感谢所有提示。
最佳答案
问题出在 Pax Runner 中,每次重新启动(干净)都会删除 Config Admin 包的数据文件夹。
要确保 Pax Runner 不会清除数据,您可以使用 --usePersistedState=true
旗帜。
关于configuration - OSGi 声明式服务和配置管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10815411/