OSGi Read Configuration Properties

I have config.propertiesin my OSGi package. but the OSGi package cannot read it.

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

I use Spring to read config.properties

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

OSGi seems to only read the file .xml. Somebody knows?

+3
source share
1 answer

You must specify the correct resource for the value property. There are several built-in implementations , for example:

  • ClassPathResource: value="classpath:/META-INF/config.properties"
  • FileSystemResource: value="file:C:/foobar/config.properties"

If you want to place the file outside the library, you can use a system property (e.g. -DpropertyFile=C:/loremIpsum/config.properties) to specify a path, e.g.

value="file:${propertyFile}"

since spring 3.0.? even with default value

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

( OSGi , . , ClassPathResource / OSGi.)

+2

All Articles