User Tools

Site Tools


Multiple Component Instances via Configuration

In OSGi it is really simple and straightforward to create a service. Services in OSGi are singletons by default.

But sometimes you need multiple instances of the same service just with different configurations. And luckily OSGi also supports this.


Just write your DS component as always as you would for a single instance component. Now add


to the component xml (or add it via annotations. I am a bit old school and still write the xml =). That means that a component will only be activated if there is a configuration for it.

You don't need to implement ManagedService for getting the configuration. So you can skip this step in your coding habit ;-).


Here comes the tricky part. The normal configuration (always using file install for picking up the configuration) has the filename like the attribute with the suffix cfg. But that would mean that we would create a normal configuration … and we wouldn't get multiple instances.

You syntax for the configuration file for multiple instances of a component (when using file install)is


The configuration file itself doesn't need the entry.

Configuration Modification

And if a configuration changes the component will be deactivated, deregistered and removed and a new component instance will be created with the updated configuration.

multiple_component_instances_via_configuration.txt · Last modified: 2015/09/24 14:44 by mihael