加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

春季-OSGi捆绑包读取配置属性

发布时间:2020-12-15 01:21:09 所属栏目:大数据 来源:网络整理
导读:我的OSGi捆绑包中有config.properties.但是OSGi捆绑包无法读取它. Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=dao,config=osgibundle:/META-INF/spring/*.xml))org.springframework.beans.factory.BeanInitializationExce

我的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属性指定正确的资源.
有一些built in implementations,例如:

> ClassPathResource:value =“ classpath:/META-INF/config.properties”
> FileSystemResource: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环境中使用.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读