It looks like there are 2 ways to read OSGi configurations
Which one is correct way? What are advantages of one over another?
Solved! Go to Solution.
Thanks smacdonald2008. Is there a way to read non-custom OSGi configuration e.g. Day CQ Mail Service etc in our code? Using ConfigurationAdmin we could directly get configuration
configurationAdmin.getConfiguration("PID of OOTB config");
Annotations seem to be working fine for custom application specific configuration (we have custom sling:Osgi config and corresponding java class), but for OOTB configurations there is already a mapping Java class in OOTB bundle, but not sure how we can use in custom bundle. If i should start a separate thread for this, let me know. But I thought its related to same thread.
Please check below example for reading log configs, similarly you can do for others :
In below example you can read OOTB web console config inside activate method also.
Thanks Arun, this example is nice, but uses ConfigurationAdmin API. I was looking for example using R6 annotations way of reading OSGi configuration.
I am not sure if you can use OSGI annotations and OCD to read configuration of other services but itself. To read configs of other services you need to use ConfigurationAdmin.
Do not read the OSGI configuration of other services. That's an antipattern for almost every case. Use the 2 methods you listed to read the configuration of a service from within this specific service, but do not use the ConfigAdmin to read any other configuration.
* If someone unfamiliar with your implementation changes some configuration, it might also affect other services.
* When your service B reads the configuration of service A, any change of the config of A will not cause a restart of your service B.
Don't do that. Don't read configuration from product bundles. If your code needs to have access to some shared configuration, build a "SharedConfigService" for it and let all consumers reference it.