Reading OSGi Configuration properties


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:

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.

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.




4 thoughts on “Reading OSGi Configuration properties

  1. First of all, there is a small typo “wil” instead “Will”.
    Secondly, I suggest include an explanation about concept “Run Mode” and how to match OSGI Configuration(the current article) and Run Mode in order to get better understanding.

  2. The explanation is great itself, very clear and compact.
    Apart from that, i’d add an explanation about run mode, how set up( –, or how to name/include for each cq/aem instance or how to define at JVM level) at difference level and how to used it.



Leave a Reply

Your email address will not be published. Required fields are marked *