title: Spring Boot executable jar and external configuration file
body: <p>I have a Spring Boot application that uses 3rd-party jar. This jar requires an xml config file, that must be provided by clients on runtime (individually) and cannot be pre-packaged. 3rd party lib loads that file using below sequence (I stripped <code>if</code>s and null-checks):</p>
  
  <pre><code>    FileConfigurator.class.getResource("/" + filename);
      Thread.currentThread().getContextClassLoader().getResource("/" + filename);
      Thread.currentThread().getContextClassLoader().getResource(filename);
  </code></pre>
  
  <p>I cannot change the way that lib loads the file (e.g. using Spring's Resource loading), so it must be on classpath. Therefore I seem to lose the possibility of executing it like <code>java -jar my-spring-boot-app.jar</code>, because <code>-jar</code> option prevents any additional classpath entries from being added. So I started running it like </p>
  
  <p><code>java -classpath my-spring-boot-app.jar:./config/: org.springframework.boot.loader.JarLauncher</code></p>
  
  <p>My directory structure is following:</p>
  
  <pre><code>|-- config
  |   |-- application.properties
  |   `-- 3rd-party-config.xml
  |-- my-spring-boot-app.jar
  </code></pre>
  
  <p>But then Spring's autowiring started to fail: Additional <code>application.properties</code> file in config directory overrides some of settings and using above command causes app startup to fail:</p>
  
  <blockquote>
    <p>Error creating bean with name 'ORBConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.company.app.communication.corba.orb.ORBConfig.serverName; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'application.corba.serverName' in string value "${application.corba.serverName}"</p>
  </blockquote>
  
  <p>Field <code>String serverName</code> is annotated with <code>@Value("${application.corba.serverName}")</code>, the property is defined in <code>application.properties</code> file bundled within JAR and value injection works fine when additional <code>application.properties</code> is not present in config dir.</p>
  
  <p>My actual question is: what is the advisable way of deploying and/or running Spring Boot application, to take advantage of executable Jar feature, provide additional classpath resources on runtime and still be able to override some (but not all) properties by classpath <code>application.properties</code> file? </p>
  
  <p>Application is packaged using spring boot maven plugin and uses <code>spring-boot-starter-parent</code> parent POM.</p>