I want to configure the list of property file locations dynamically.
Basically each of my environments (dev,stage,prod) have a particular
hierachy of property file overrides and the list has to be determined at
runtime.

Rather than as below statically listing them in my spring config file:

          <bean id="properties"
class="org.apache.camel.component.properties.PropertiesComponent">
            <property name="locations"
value="file:config/config.properties,file:config/config-dev.properties" />
          </bean>

I want to calculate a dynamic list, I've worked out how todo this when using
CamelTestSupport by overriding createCamelContext.

          @Override
          protected CamelContext createCamelContext() throws Exception {
            CamelContext context = super.createCamelContext();

            // Load test specific properties
            PropertiesComponent properties =
context.getComponent("properties",PropertiesComponent.class);
            properties.setLocations(myDynamicLocations);
      

But how can I do this from my actual route that extends RouteBuilder?, I
tried overriding createContainer but this doesnt seemed to get called.

        public class RadialRouteBuilder extends RouteBuilder {


          /**
           * A main() so we can easily run these routing rules in our IDE
           *
           * @param args command line arguments
           * @throws Exception exception that terminated running of main thread
           */
          public static void main(String... args) throws Exception {
            Main.main(args);
          }

          @Override
          protected CamelContext createContainer() {
            CamelContext context = super.createContainer();

            PropertiesComponent properties = new PropertiesComponent();
            properties.setLocations(myDynamicLocations);
            context.addComponent("properties", properties);

            return context;
          }

This just ends with me getting exception:

Caused by: java.lang.IllegalArgumentException: PropertiesComponent with name
properties must be defined in CamelContext to support property placeholders.
        at
org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:969)
        at
org.apache.camel.model.ProcessorDefinition.resolvePropertyPlaceholders(ProcessorDefinition.java:500)
        at
org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:426)
        at
org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:183)
        at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:791)
        ... 26 more

I may be trying to use a sledge hammer to crack a nut, so there may be an
easier way of doing this. The main point is that the exact list of
properties files are not known until runtime, this may be unusual but is
just the way it is!

--
View this message in context: 
http://camel.465427.n5.nabble.com/Dynamically-configuring-list-of-property-file-locations-in-context-tp4704591p4704591.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to