snow8261
snow8261

Reputation: 1009

OSGi bundle read config properties

I have config.properties in my OSGi bundle. but the OSGi bundle can not 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 am using Spring to read the config.properties

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

It seems like the OSGi only reads the .xml file. Does someone has any idea?

Upvotes: 3

Views: 2924

Answers (1)

FrVaBe
FrVaBe

Reputation: 49361

You have to specify the correct resource for your value property. There are some built in implementations, like:

  • 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 the path, like

value="file:${propertyFile}"

since Spring 3.0.? even with default value

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

(Have a look at your OSGi framework on how to set a system property. I am also not sure if the ClassPathResource works well / is recommended in OSGi environments.)

Upvotes: 3

Related Questions