Configuration OSGi声明性服务和配置管理
我正在使用声明性服务编写包。对于配置,我在DS声明中使用属性。这些道具通常可以由配置管理员更改,但不会持久化。容器重新启动后,组件具有默认值 我使用的配置管理员如下:Configuration OSGi声明性服务和配置管理,configuration,osgi,declarative-services,Configuration,Osgi,Declarative Services,我正在使用声明性服务编写包。对于配置,我在DS声明中使用属性。这些道具通常可以由配置管理员更改,但不会持久化。容器重新启动后,组件具有默认值 我使用的配置管理员如下: Configuration c = configurationAdmin.getConfiguration(UserAgent.SERVICE_PID, null); System.out.println(c.getProperties()); // every time is null! Dictionary props = n
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中,每次重新启动(清除)都会删除配置管理包的数据文件夹 为了确保Pax Runner不清除数据,您可以使用
--usePersistedState=true
标志。仅供参考,您可能希望在激活/停用/修改操作中使用(映射属性)签名,以避免代码中包含OSGi API。