Read config nodes inside a non service class | Community
Skip to main content
Level 3
Sep 13, 2017 7:31 AM UTC
Solved

Read config nodes inside a non service class

How to read config nodes inside a non service class.

I have a configuration created in felix console. I want to read that property in one of my helper class.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
minisanuAccepted solution
Level 3
Oct 9, 2017 6:51 AM UTC

Thanks Everyone...Sorry for the delayed reply..I lost track of my password and got it reset again. I have created a configAdmin and it is working fine

5 replies

minisanuAuthorAccepted solution
Level 3
Oct 9, 2017 6:51 AM UTC

Thanks Everyone...Sorry for the delayed reply..I lost track of my password and got it reset again. I have created a configAdmin and it is working fine

Translate
joerghoh
Employee
Sep 13, 2017 8:42 PM UTC

Do not use the ConfigAdmin directly, I would consider this an Antipattern. A service/component should only read its own properties, but not read the property of other services, these are typically implementation details. If you really need to know something about other services, extend their interface and provide the information via the public API of this service. Then the compiler can support you to write robust code.

Jörg

Translate
Ratna_Kumar
Level 10
Sep 13, 2017 4:15 PM UTC

Hi,

I agree with Scott!! You should look into the article mentioned

//Adobe Experience Manager Help | Reading Adobe Experience Manager OSGi Configuration Values

~Ratna

Translate
smacdonald2008
Level 10
Sep 13, 2017 4:04 PM UTC

We have an article that shows you how to read node values -- Scott's Digital Community: Reading AEM OSGi Configuration Values

Translate
viveksachdeva
New Participant
Sep 13, 2017 8:52 AM UTC

To read values of config, you need to get reference of ConfigurationAdmin which is only possible if your class is an OSGi component. If there is a helper class where you want to read such properties, you need to pass ConfigurationAdmin object to that method and then read the properties.

Something like:

String fetchConfigValue(ConfigurationAdmin cfgAdmin, String pid, String key){

....

}

Translate