อัปเดตครั้งล่าสุดเมื่อ
21 ธ.ค. 2021
How to read OSGi configurations which are not bound to the executing component.
Environment
Steps
The recommended approach to reading various OSGi configurations is to use the ConfigurationAdmin [1], not to search for the config files in your application. See the sample code here [2].
[1] https://osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html
[2] http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.html
The ConfigurationAdmin is an OSGi service so it can be obtained via SCR annotation in your own OSGi component code. Example below (org.sample.PrettyPrinterConfigurator is the PID of the configuration):
@Reference ConfigurationAdmin configAdmin; @Activate public void activate(ComponentContext componentContext) { Configuration config = configurationAdmin.getConfiguration( "org.sample.PrettyPrinterConfigurator"); Dictionary props = config.getProperties(); }