Having talking about different ways of managing OSGi configuration here, I would like to extend from there and talk about

  1. how to create the configuration properties for a service
  2. how to read the configuration values in the service.

How to Create the configurable properties:

@Service(value = ConfigurationServiceImpl.class)

@Component(immediate = true, metatype = true, label = "Example Configuration Service")

public class ConfigurationServiceImpl implements ConfigurationService {

    private static final Logger LOG = LoggerFactory.getLogger(ConfigurationServiceImpl.class);

    private static final String CLASS_NAME = "[ConfigurationService]: ";

    @Property(unbounded = PropertyUnbounded.ARRAY, label = "Multi String", cardinality = 50, description = "Example for Multi field config")

    private static final String MULTI_FIELD = "multifield";

    @Property(unbounded = PropertyUnbounded.DEFAULT, label = "Simple String", description = "Example for Simple text field config")

    private static final String SIMPLE_FIELD = "simplefield";

As shown in the above example,

Use @Property annotation for the variable.

  • Data type of the variable determines the type of value it can hold
  • Set ‘Unbounded’ attribute as ARRAY if it’s a ‘multi’ property else assign it as DEFAULT
  • Give the ‘label and ‘description’ to be shown in the /system/console/configMgr
  • Add ‘metatype=true’ attribute for @Component to enable the properties as configurable values.

As soon as we have done this, you will able to configure the values for these properties via configMgr

But the best way is to create the different configuration based on the run modes if the values are difference in each mode and the same can be done by creating the config files under /apps as shown below.

Config Runmodes

Config Runmodes

Add the properties with the name given in the services like ‘multifield’ and ‘simplefield’ along with their values and save.

Config Properties

Config Properties

Now, Let us see how to read these values.

protected void readProperties(final Map<String, Object> properties) {


        this.multiString = PropertiesUtil.toStringArray(properties.get(MULTI_FIELD));

        LOG.info("Mutli String Size: " + multiString.length);       

        this.simpleString = PropertiesUtil.toString(properties.get(SIMPLE_FIELD),"default");

        LOG.info("Simple String: " + simpleString);


Above method is an example on how to read the properties.

You can download the project from the github here. Also click here to refer my Adobe article on this in detail.