How to read OSGi configurations not bound to the component's code

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

 Adobe

更快、更輕鬆地獲得協助

新的使用者?

Adobe MAX 2024

Adobe MAX
創意大會

10 月 14 至 16 日邁阿密海灘和線上

Adobe MAX

創意大會

10 月 14 至 16 日邁阿密海灘和線上

Adobe MAX 2024

Adobe MAX
創意大會

10 月 14 至 16 日邁阿密海灘和線上

Adobe MAX

創意大會

10 月 14 至 16 日邁阿密海灘和線上