我有使用配置文件org.jemz.karaf.tutorial.hello.service.config.cfg
有一个属性捆绑:Karaf添加额外的属性,以现有的配置文件
org.jemz.karaf.tutorial.hello.service.msg="I am a HelloServiceConfig!!"
我使用ConfigAdmin蓝图是这样的:
<cm:property-placeholder persistent-id="org.jemz.karaf.tutorial.hello.service.config" update-strategy="reload" >
<cm:default-properties>
<cm:property name="org.jemz.karaf.tutorial.hello.service.msg" value="Hello World!"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="hello-service-config"
class="org.jemz.karaf.tutorial.hello.service.config.internal.HelloServiceConfig"
init-method="startup"
destroy-method="shutdown">
<property name="helloServiceConfiguration">
<props>
<prop key="org.jemz.karaf.tutorial.hello.service.msg" value="${org.jemz.karaf.tutorial.hello.service.msg}"/>
</props>
</property>
</bean>
<service ref="hello-service-config" interface="org.jemz.karaf.tutorial.hello.service.IHelloService" />
这工作正常只要我可以更改该属性的值并且该包自动更新该属性。
我想知道是否有任何添加新的属性到我的配置文件,而不必改变蓝图(这涉及到编译/包再次)的任何方式。当然,我的包应该准备好处理新的属性。
不知道这在OSGi中是否有意义。任何人都可以给我提示如何动态地将新属性添加到现有配置文件并使其在ConfigAdmin中可用?
你也可以使用一个类来实现ConfigurationListener ,BundleContextAware'接口。然后,您将收到有关配置更改的所有事件,因此您可以在应用程序中处理任何您想要的内容 – yodamad