OSGi Declarative Services and Config Admin

1.9k Views Asked by At

I'm writting bundle with declarative services usage. For configuration I'm using properties in DS declaration. Those props can be normally changed by Config Admin, but they are not persisted. After container restart, component has default values.

I'am using Config admin like this:

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);

and in component I have:

// ...

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

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

I'm using Felix, properties file is stored in cache

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

But after restart isn't loaded. What I'm doing wrong? Thanks for all tips.

1

There are 1 best solutions below

0
On BEST ANSWER

Problem was in Pax Runner which every restart (clean) erased the data folder of Config Admin bundle.

To make sure that Pax Runner does not clear the data, you can use the --usePersistedState=true flag.