title: Spring boot how to pick externalized spring properties file
body: <p>I have this configurations which needs to be used for a spring boot application.</p>
  
  <pre><code>server.port=8085
  server.servlet.context-path=/authserver
  #data source
  spring.jpa.hibernate.ddl-auto=none
  spring.datasource.url=&lt;url&gt;
  spring.datasource.username=&lt;username&gt;
  spring.datasource.password=&lt;password&gt;
  spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
  </code></pre>
  
  <p>By default spring-boot picks up up the application.properties file located in src/main/resources/</p>
  
  <p>I want to alter this path and direct spring boot to different application.properties file</p>
  
  <p>I can achieve this using </p>
  
  <pre><code>java -jar app.jar --spring.config.location=classpath:/another-location.properties  
  </code></pre>
  
  <p>Is there any any alternative solution I can achieve this without passing args through command line?</p>
  
  <p>I was using this</p>
  
  <pre><code>   @PropertySource("file:C:\Users\test\.test\test.properties")
      @ConfigurationProperties(prefix = "spring")
      public class Configuration {
  
          private String ddlAuto;
  
          private String url;
  
          private String username;
  
          private String password;
  
          private String driverClassName;
      }
  </code></pre>
  
  <p>in my Main class</p>
  
  <pre><code>@SpringBootApplication
  @EnableConfigurationProperties(Configuration.class)
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
  }
  </code></pre>
  
  <p>There after I tried executing the app commenting out all datasource properties in application.properties under src/main/resources/ 
  But it keeps giving me the error mentioned bellow and application fails to start</p>
  
  <p>I was referring this tutorial : <a href="https://www.mkyong.com/spring-boot/spring-boot-configurationproperties-example/" rel="nofollow noreferrer">https://www.mkyong.com/spring-boot/spring-boot-configurationproperties-example/</a></p>
  
  <p>but as it's mentioned I get this error when i start the spring boot application</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Binding to target org.springframework.boot.context.properties.bind.BindException: 
  </code></pre>
  
  <p>Any help on this would be appreciated  </p>