Spring OSGi包读取配置属性

Spring OSGi包读取配置属性,spring,osgi,Spring,Osgi,我的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 propertie

我的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
文件。
有人知道吗?

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

  • ClassPathResource:
    value=“classpath:/META-INF/config.properties”
  • FileSystemResource:
    value=“file:C:/foobar/config.properties”
如果要将文件放在库外部,可以使用系统属性(例如
-DpropertyFile=C:/loremIpsum/config.properties
)指定路径,如

value="file:${propertyFile}"
从3.0春季开始。?即使使用默认值

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

(查看一下您的OSGi框架,了解如何设置系统属性。我也不确定ClassPathResource在OSGi环境中是否工作良好/是否推荐。)

找不到您的config.properties文件。它在您的包中的什么位置?我把它放在META-INF文件夹中。我想找到一种方法,将配置文件放在bundle之外,并像全局配置设置一样进行操作。可能吗?