title: Can I manually load @ConfigurationProperties without the Spring AppContext?
body: <p>Is there any way to load a class marked with <code>@ConfigurationProperties</code> without using a Spring Context directly? Basically I want to reuse all the smart logic that Spring does but for a bean I manually instantiate outside of the Spring lifecycle.  </p>
  
  <p>I have a bean that loads happily in Spring (Boot) and I can inject this into my other Service beans: </p>
  
  <pre><code>@ConfigurationProperties(prefix="my")
  public class MySettings {
      String property1;
      File property2;
  } 
  </code></pre>
  
  <p>See the spring docco for more info <a href="http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-command-line-args" rel="noreferrer">http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-command-line-args</a></p>
  
  <p>But now I need to access this bean from a class that is created outside of Spring (by Hibernate). The class is created so early in the app startup process that Spring Boot has not yet made the application context available through the classic lookup helper methods or roll-my-own static references. </p>
  
  <p>So I instead want to do something like: </p>
  
  <pre><code>MySettings mySettings = new MySettings(); 
  SpringPropertyLoadingMagicClass loader = new SpringPropertyLoadingMagicClass();
  loader.populatePropertyValues(mySettings);
  </code></pre>
  
  <p>And have MySettings end up with all its values loaded, from the command line, system properties, app.properties, etc. Is there some class in Spring that does something like this or is it all too interwoven with the application context? </p>
  
  <p>Obviously I could just load the Properties file myself, but I really want to keep Spring Boot's logic around using command line variables (e.g. --my.property1=xxx), or system variables, or application.properties or even a yaml file, as well as its logic around relaxed binding and type conversion (e.g. property2 is a File) so that it all works exactly the same as when used in the Spring context.</p>
  
  <p>Possible or pipe dream?</p>
  
  <p>Thanks for your help! </p>