OSGI捆绑包:当其中包含“ =”时,ConfigurationAdmin会截断密钥

问题描述 投票:1回答:1

我有一个运行在Karaf中的OSGI Bundle。我的捆绑包通过ConfigurationAdmin检索所有配置。我迭代所有配置以获取属性。

我对属性的密钥有疑问。该属性具有此键-值

“ setStartLevel(java.lang.String,= int)[/([1-4])?[0-9] /,/.*/] = admin”

正如您所看到的,键内部有一个“ =”(在“ int”之前)。

ConfigurationAdmin还给我:

KEY =“ setStartLevel(java.lang.String,”

VALUE =“ int)[/([1-4])?[0-9] /,/.*/] = admin”

这是我的代码,我只检索属性:

configs = this.configurationAdmin.listConfigurations(null);
for (Configuration cfg : configs) {
        Dictionary<String, Object> properties = cfg.getProperties();
        Collections.list(properties.keys()).forEach(key -> {
            System.out.println("KEY: "+key);
            System.out.println("VALUE: "+properties.get(key));
                 }
        }

关于如何告诉ConfigurationAdmin检索正确的键值的任何想法?

java apache-karaf osgi-bundle
1个回答
0
投票

用反斜杠“ \”转义第一个“ =”

 % cat io.hyte.foo.cfg 
 hello=world
 foo\=bar=blah

在Karaf中确认值

   karaf@root()> config:list "(service.pid=io.hyte.foo)"
   ----------------------------------------------------------------
   Pid:            io.hyte.foo
   BundleLocation: ?
   Properties:
       felix.fileinstall.filename = file:...etc/io.hyte.foo.cfg
       foo=bar = blah
       hello = world
       service.pid = io.hyte.foo
© www.soinside.com 2019 - 2024. All rights reserved.