如何在 OSGi 蓝图中指定 属性 文件的位置?
How can I specify location of property file in OSGi blueprint?
我想指定 属性 文件的位置,OSGi 蓝图 属性 占位符应从中读取属性值:
<cm:property-placeholder persistent-id="myBundle"/>
<bean
id="myCoolBean"
class="test.properties.MyCoolBean">
<property
name="echo"
value="${echo}"/>
</bean>
更新:
配置 felix.configadmin + felix.fileinstall 对我有用。
我安装了:
org.apache.felix.configadmin-1.8.0.jar
org.apache.felix.fileinstall-3.1.4.jar
org.eclipse.equinox.cm-3.2.0.jar
我指定了 VM 参数 -Dfelix.fileinstall.dir=C:/eclipse/config
myBundle.cfg 文件具有以下价值:
回声=回声
蓝图中的 属性 占位符不适用于文件。相反,它使用持久性 ID 从 ConfigurationAdmin 服务中检索配置。
所以解决方法是将felix config admin和felixfileinstall一起安装。因此配置将从文件夹中检索并在 ConfigurationAdmin 中更新。
在 apache karaf 中,这已经配置好了,但您也可以自己配置。看我的 karaf tutorial about config admin.
如果您想使用普通的 felix,那么您可以看看 karaf 是如何解决它的。例如,在 config.properties 中有 felix fileinstall 的设置。在那里你必须例如设置包含您的配置的目录。在普通的 felix 中,这将是框架属性。
这是 karaf 设置的:
felix.fileinstall.enableConfigSave = true
felix.fileinstall.dir = ${karaf.etc}
felix.fileinstall.filter = .*\.cfg
felix.fileinstall.poll = 1000
felix.fileinstall.noInitialDelay = true
felix.fileinstall.log.level = 3
我想指定 属性 文件的位置,OSGi 蓝图 属性 占位符应从中读取属性值:
<cm:property-placeholder persistent-id="myBundle"/>
<bean
id="myCoolBean"
class="test.properties.MyCoolBean">
<property
name="echo"
value="${echo}"/>
</bean>
更新: 配置 felix.configadmin + felix.fileinstall 对我有用。
我安装了:
org.apache.felix.configadmin-1.8.0.jar
org.apache.felix.fileinstall-3.1.4.jar
org.eclipse.equinox.cm-3.2.0.jar
我指定了 VM 参数 -Dfelix.fileinstall.dir=C:/eclipse/config
myBundle.cfg 文件具有以下价值:
回声=回声
蓝图中的 属性 占位符不适用于文件。相反,它使用持久性 ID 从 ConfigurationAdmin 服务中检索配置。
所以解决方法是将felix config admin和felixfileinstall一起安装。因此配置将从文件夹中检索并在 ConfigurationAdmin 中更新。
在 apache karaf 中,这已经配置好了,但您也可以自己配置。看我的 karaf tutorial about config admin.
如果您想使用普通的 felix,那么您可以看看 karaf 是如何解决它的。例如,在 config.properties 中有 felix fileinstall 的设置。在那里你必须例如设置包含您的配置的目录。在普通的 felix 中,这将是框架属性。
这是 karaf 设置的:
felix.fileinstall.enableConfigSave = true
felix.fileinstall.dir = ${karaf.etc}
felix.fileinstall.filter = .*\.cfg
felix.fileinstall.poll = 1000
felix.fileinstall.noInitialDelay = true
felix.fileinstall.log.level = 3