Sharing Configurations in ConfigAdmin

by kengilmer

It took me a few hours of fruitless searching and some experimentation before I figured how to let multiple bundles get notifications for configuration updates using ConfigAdmin.  This is a core use case [1] over simpler, more traditional configuration mechanisms such as system properties, but I was initially unable to find out how to get it working.

Essentially ConfigAdmin uses the bundleLocation to determine if configuration information should be shared.  If, when creating a configuration, a location is not specified [2], the calling bundle is used.  From this point other bundles wishing to register a ManagedService with the same PID will get an error.  The key is in specifying null for location [3] in the bundle or bundles that would be creating and writing to a shared configuration.

Dynamic configuration is quite useful in long-running systems and once I figured out the correct way to create the configuration, everything else was straight-forward.  Now to figure out an easy way to migrate my existing static configurations to use ConfigAdmin…

3:, java.lang.String)