title: spring boot property with profile from dependency
body: <p><strong>Problem:</strong></p>
  
  <p>I have 3 parts in the software:</p>
  
  <ul>
  <li>Client A service</li>
  <li>Client B service</li>
  <li>Target C service</li>
  </ul>
  
  <p>I want to connect to C from A and B<br>
  I wrote a library with following setup:</p>
  
  <ul>
  <li>/src/main/java/pkg.../TargetConnector.java</li>
  <li>/src/main/java/pkg.../TargetConfig.java</li>
  <li>/src/main/resources/application-dev.properties</li>
  <li>/src/main/resources/application-tst.properties</li>
  <li>/src/main/resources/application-prd.properties</li>
  </ul>
  
  <p>My clients A and B both have there own sources and properties:</p>
  
  <ul>
  <li>/src/main/java/pkg.../Client{A/B}Service.java</li>
  <li>/src/main/java/pkg.../Client{A/B}Config.java</li>
  <li>/src/main/resources/application-dev.properties</li>
  <li>/src/main/resources/application-tst.properties</li>
  <li>/src/main/resources/application-prd.properties</li>
  </ul>
  
  <p>The properties of the Connector contains some login info for the service e.g. </p>
  
  <pre><code>target.url=https://....
  target.usr=blablabla
  target.key=mySHAkey
  </code></pre>
  
  <p>which is used in the TargetConfig to preconfigure the Connector e.g.</p>
  
  <pre><code>@Value("target.url")
  String url;
  @Value("target.usr")
  String usr;
  @Value("target.key")
  String key;
  
  @Bean
  public TargetConnector connector() {
    return new TargetConnector(url, usr, key);
  }
  </code></pre>
  
  <p>Now when I use the connector jar in the client I can find the configuration via packagescan. The connector class is loaded but the problem is that it does not load the properties files.  </p>
  
  <p><strong>Research</strong></p>
  
  <p>I found that multiple property files cannot have the same name (e.g. clients application-{profile}.properties clashes with the one from the connector), so I tried to rename <strong>application-{profile}.properties</strong> of the targetConnector to <strong>application-connector-{profile}.properties</strong>.<br>
  The properties whoever still do not get loaded, (which makes sense since I do not have a e.g <strong>connector-dev</strong> profile but my profile is simply named <strong>dev</strong>).</p>
  
  <p>Furthermore, even if I try to explicitly load one of the property files from the connector with: </p>
  
  <pre><code>@PropertySource({"classpath*:application-connector-dev.properties"}) 
  </code></pre>
  
  <p>it cannot be found</p>
  
  <p><strong>Question</strong></p>
  
  <p>My question is actually 3 tiered:</p>
  
  <ol>
  <li>How can I load a property file in a dependency jar at all?</li>
  <li>How can I load the profiled version of the property file if the the properties file has a different name than application.properties? e.g. application-connector.properties</li>
  <li>How can i combine the answers from question 1 and 2 to load the profiled version of the property in the jar? </li>
  </ol>
  
  <p>If further explanation is needed, please ask.</p>
  
  <p><strong>Answer</strong></p>
  
  <p>I went for an approach as given in the accepted answer. 
  I Just created 3 configs for the dev, tst, prd profiles containing the values needed and annotated the config files with the correct profiles.</p>