2 Replies Latest reply on Feb 19, 2013 12:01 PM by Constantine Vasilyev

    How do I make Blueprint resolve placeholders from multiple files?

    Constantine Vasilyev Newbie

      So far, I have been successfully using a single .cfg file for Blueprint to resolve property placeholders. In my Blueprint config file I have the following:

       

      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
                 xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
      
        <cm:property-placeholder persistent-id="myapp" update-strategy="reload"></cm:property-placeholder>
      
        <bean id="someBean" class="com.mycompany.myapp.MyClass">
              <property name="someProp"  value="${some.prop.from.myapp.cfg}"></property>
        </bean>
      
      ...
      </blueprint>
      

       

      I have other legacy .properties files that I must keep. The files live in <karaf-home>/etc/conf directory. I would like some of the properties in those files to also be accessible and resolved within my Blueprint context files. I have tried adding the following:

       

      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
                 xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
                 xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
      
             <cm:property-placeholder persistent-id="myapp" update-strategy="reload"></cm:property-placeholder>
             <ext:property-placeholder placeholder-prefix="${" placeholder-suffix="}">
                  <ext:location>file:conf/other.properties"</ext:location>
              </ext:property-placeholder>
      
             <bean id="someBean" class="com.mycompany.myapp.MyClass">
                  <property name="someProp"  value="${some.prop.from.myapp.cfg}"></property>
                  <property name="anotherProp"  value="${some.prop.from.other.properties}"></property>
             </bean>
       

       

      but that didn't work. I have also tried changing the place-holder's prefix and suffix for the second definition from {} to [] or (), adjusting the value accordingly, e.g.  "=$(...)"  That didn't work either.

       

      What is the correct way to load properties from an external .properties file into Blueprint (in addition to using a .cfg file)?

       

      Thanks,

      Constantine

        • 2. Re: How do I make Blueprint resolve placeholders from multiple files?
          Constantine Vasilyev Newbie

          Freeman, thanks, but I think this is exactly what I have been doing, and I couldn't get it to work. Please take a look at my code example above. Am I using the value for the location property correctly, assuming my properties file is in etc/conf directory?  It is still not clear to me how to combine the "standard"  <cm:property-placeholder> usage with <ext:property-placeholder /> so that the properties are resolved from both the .cfg file and some other regular .properties file(s).

           

          When I define both placeholder resolvers - as shown in my example above - I always get the following error during the bundle initialization:

           

          2013-02-19 11:33:16,924 | ERROR | rint Extender: 3 | BlueprintContainerImpl           | 9 - org.apache.aries.blueprint - 0.3.2 | Unable to start blueprint container for bundle com.mycompany.myapp.myservice
          org.osgi.service.blueprint.container.ComponentDefinitionException: Multiple placeholders with the same prefix and suffix are not allowed
               at org.apache.aries.blueprint.ext.PlaceholdersUtils.validatePlaceholder(PlaceholdersUtils.java:48)[9:org.apache.aries.blueprint:0.3.2]
               at org.apache.aries.blueprint.ext.ExtNamespaceHandler.parsePropertyPlaceholder(ExtNamespaceHandler.java:245)[9:org.apache.aries.blueprint:0.3.2]
               at org.apache.aries.blueprint.ext.ExtNamespaceHandler.parse(ExtNamespaceHandler.java:113)[9:org.apache.aries.blueprint:0.3.2]
               at org.apache.aries.blueprint.container.Parser.parseCustomElement(Parser.java:1248)[9:org.apache.aries.blueprint:0.3.2]
               at org.apache.aries.blueprint.container.Parser.loadComponents(Parser.java:337)[9:org.apache.aries.blueprint:0.3.2]
               at org.apache.aries.blueprint.container.Parser.populate(Parser.java:277)[9:org.apache.aries.blueprint:0.3.2]
               at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:283)[9:org.apache.aries.blueprint:0.3.2]
               at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:230)[9:org.apache.aries.blueprint:0.3.2]
          

           

          Note that it happens even when I define distinct prefix and suffix for the ext placeholders, e.g. "$(" and ")" - parenthesis instead of curly brackets.