【问题标题】:OSGi bundle read config propertiesOSGi 包读取配置属性
【发布时间】:2012-05-03 08:16:12
【问题描述】:

我的 OSGi 包中有 config.properties。但 OSGi 包无法读取它。

Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=dao, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException

我正在使用Spring阅读config.properties

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="config.properties" />
</bean>

OSGi 似乎只读取.xml 文件。 有人知道吗?

【问题讨论】:

  • 找不到您的 config.properties 文件。它位于您的捆绑包中的什么位置?
  • 我把它放在 META-INF 文件夹中。我想找到一种方法将配置文件放在捆绑包之外,并且行为类似于全局配置设置。有可能吗?

标签: spring osgi


【解决方案1】:

您必须为您的 value 属性指定正确的资源。 还有一些built in implementations,比如:

  • 类路径资源:value="classpath:/META-INF/config.properties"
  • 文件系统资源:value="file:C:/foobar/config.properties"

如果您想将文件放在库之外,您可以使用系统属性(例如-DpropertyFile=C:/loremIpsum/config.properties)来指定路径,例如

value="file:${propertyFile}"

自 Spring 3.0 以来。?即使使用默认值

value="file:${propertyFile:C:/foobar/config.properties}"

查看您的 OSGi 框架,了解如何设置系统属性。我也不确定 ClassPathResource 是否在 OSGi 环境中运行良好/是否推荐使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 2022-07-06
    • 1970-01-01
    • 2015-03-13
    • 2018-03-03
    • 2018-06-15
    • 2019-02-09
    相关资源
    最近更新 更多