Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Read config nodes inside a non service class

minisanu
Level 3
Level 3

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.

1 Accepted Solution
minisanu
Correct answer by
Level 3
Level 3

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

View solution in original post

5 Replies
viveksachdeva
Level 7
Level 7

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){

....

}

Jörg_Hoh
Employee
Employee

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

minisanu
Correct answer by
Level 3
Level 3

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

View solution in original post