title: Camel: Optional external properties file
body: <p>My use case is that I have a route, which for which I want to configure the autoStartup through an optional property. I was thinking that I can use the @PropertyInject annotation to fetch this property, and use a default value if the property has not been set. Example:</p>
  
  <pre><code>@PropertyInject(value = "message.import.item.autoStartup", defaultValue = "true")
  private String autoStartup;
  
  public void configure() throws Exception {
  
      from("{{message.import.item}}?clientId=2&amp;durableSubscriptionName=ItemSubscriber")
                      .to("{{message.import.source}}")
                      .autoStartup(autoStartup);
  
  }
  </code></pre>
  
  <p>I have created a property placeholder in my camel context with two property files, one on the classpath which is always present in the packaged jar file, and the second one being the external file that I want to be optional:</p>
  
  <pre><code>&lt;camelContext streamCache="true" xmlns="http://camel.apache.org/schema/spring"&gt;
      &lt;propertyPlaceholder id="properties" location="file:${camel.subscribers}/subscriber.properties,classpath:integration.properties" ignoreMissingLocation="true"/&gt;
      &lt;contextScan/&gt;
  &lt;/camelContext&gt;
  </code></pre>
  
  <p>As long as I provide a value for camel.subscribers as a JVM property, this works as expected. If the subscriber.properties file is not present, the default value is loaded through the @PropertyInject annotation, and if it is present and contains the corresponding key, the value is loaded from the properties file.</p>
  
  <p>However I have one issue: Remember that I wanted this properties file to be optional. The existance of the file itself is indeed optional, but this setup REQUIRES that I provide a value for camel.subscribers. Unless I do, I get a IllegalArgumentException:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'camel.subscribers' in string value "file:${camel.subscribers}/subscriber.properties,classpath:integration.properties"
  </code></pre>
  
  <p>This kind of defeats the whole purpose of have the property as optional, as it forces me to provide a value for camel.subscribers, just to be able to find out that the file subscriber.properties does not exist.</p>
  
  <p>Am I approaching this the wrong way? Any other thoughts on how to solve this problem?</p>