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();
}

Questo prodotto è concesso in licenza in base alla licenza di Attribuzione-Non commerciale-Condividi allo stesso modo 3.0 Unported di Creative Commons.  I post su Twitter™ e Facebook non sono coperti dai termini di Creative Commons.

Note legali   |   Informativa sulla privacy online