Osgi 从java访问Karaf cfg文件中的属性?

Osgi 从java访问Karaf cfg文件中的属性?,osgi,config,karaf,blueprint,property-placeholder,Osgi,Config,Karaf,Blueprint,Property Placeholder,我正在蓝图中使用cm:property占位符加载配置文件: <!-- External configuration --> <cm:property-placeholder persistent-id="mubyndle" update-strategy="reload"> <cm:default-properties> <cm:property name="schemaValidation" value="false"/>

我正在蓝图中使用cm:property占位符加载配置文件:

<!-- External configuration -->
<cm:property-placeholder persistent-id="mubyndle" update-strategy="reload">
    <cm:default-properties>
        <cm:property name="schemaValidation" value="false"/> 
    </cm:default-properties>
</cm:property-placeholder>

<bean id="myBean" class="com.mybean">
    <property name="abc" value="${abc}" />
</bean>

我可以将值设置为bean,比如${abc}
如何从java访问配置的任何其他属性

我计划添加以下财产清单: prop1=11 prop2=22 ... propn=nn

由于数量不同,我无法在蓝图中添加所有内容

谢谢,,
Viktor

您可以在myBean中设置
org.apache.aries.blueprint.compendium.cm.CmPropertyPlaceholder

作为

在给定id后
在blueprint中添加对ConfigurationAdmin服务的引用:

将其设置为bean:

在bean中:
private ConfigurationAdmin configAdmin

public void setConfigAdmin(ConfigurationAdmin configAdmin) throws IOException {
    this.configAdmin = configAdmin;

    System.out.println(configAdmin);
    System.out.println(configAdmin.getConfiguration("any-persistent-id").getProperties());
}
你最好这样做:

a) 在blueprint.xml中

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"

b) “豆子”里面

  • 定义公共构造函数(Spring需要定义)
  • 定义变量及其设置程序:
private;
public(){}//无参数
公共无效集(){
= ;
}
c) 将配置文件添加到“/etc”文件夹中:

.cfg

显然,在它里面,财产:

=


您还可以看看这个线程:问题是如何设置值列表,这些值不是逗号分隔的,而是在配置文件中每行定义一个。
<cm:property-placeholder persistent-id="<name of cfg file>"
    update-strategy="reload">
    <cm:default-properties>
        <cm:property name="<property name in file>" value="<value>" />
    </cm:default-properties>
</cm:property-placeholder>


<bean id="<name of Bean>" class="<full name of class>" >
    <property name="<property name in file>" value="${<value>}"></property>
</bean>
private <Type of> <name of variable>;
public <Constructor> (){} // no parameters
public void  set<property name in file first upper letter>(<Type of> <property name in file>) {
  <name of variable> = <property name A>;
}