3

config.properties的 OSGi 包中有。但 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文件。有人有什么想法吗?

4

1 回答 1

3

您必须为您的 value 属性指定正确的资源。有一些内置的实现,例如:

  • 类路径资源: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 环境中使用。

于 2012-05-04T19:31:47.523 回答