Search code examples
osgiblueprint-osgi

How can I specify location of property file in OSGi blueprint?


I would like to specify location of property file, from which OSGi blueprint property placeholder should read properties values:

<cm:property-placeholder persistent-id="myBundle"/>

<bean
    id="myCoolBean"
    class="test.properties.MyCoolBean">
    <property
        name="echo"
        value="${echo}"/>
</bean>

UPDATE: Configuration felix.configadmin + felix.fileinstall works for me.

I installed:

org.apache.felix.configadmin-1.8.0.jar

org.apache.felix.fileinstall-3.1.4.jar

org.eclipse.equinox.cm-3.2.0.jar

I specified VM argument -Dfelix.fileinstall.dir=C:/eclipse/config

The myBundle.cfg file has value:

echo=Echo


Solution

  • The property placeholder in blueprint does not work with files. Instead it uses the persistent id to retreive a config from ConfigurationAdmin service.

    So the solution is to install felix config admin together with felixfileinstall. So configs will be retrieved from a folder and updated in ConfigurationAdmin.

    In apache karaf this is already configured but you can also do it on your own. See my karaf tutorial about config admin.

    If you want to go with plain felix then you can take a look what karaf does to solve it. So for example in config.properties there are the settings for felix fileinstall. There you have to e.g. set he directory containing your configs. In plain felix that would be framework properties.

    This is what karaf sets:

    felix.fileinstall.enableConfigSave = true
    felix.fileinstall.dir    = ${karaf.etc}
    felix.fileinstall.filter = .*\\.cfg
    felix.fileinstall.poll   = 1000
    felix.fileinstall.noInitialDelay = true
    felix.fileinstall.log.level = 3