title: How to access Class member variables from SpringApplication in Spring Boot
body: <p>How do you access a member variable when starting the application using SpringApplication in SpringBoot ?</p>
  
  <p>In the below code I am getting compilation errors on the assignment to <code>Environment</code> and <code>BuildProperties</code>. I think there must be a way to reference these properties via the <code>SpringApplication</code> or <code>ConfigurableApplicationContext</code> but I don't know how.</p>
  
  <p>The compile error I am getting is, 
  <code>non-static variable environment cannot be referenced from a static context</code>
  which I understand its just how to get around it.</p>
  
  <p>I think my question really is - does SpringApplication return a Class level reference in the same way as doing a normal java MyClass myClass = new MyClass() does ?  </p>
  
  <pre><code>@Slf4j
  @EnableIntegration
  @EnableLoaderApplication
  @SpringBootApplication
  @EnableDiscoveryClient
  public class ExampleApplication {
  
      private Environment environment;
      private BuildProperties buildProperties;
  
      public ExampleApplication(Environment env, BuildProperties buildProp) {
          environment = env;
          buildProperties = buildProp;
      }
  
      public static void main(String[] args) {
          SpringApplication app = new SpringApplication(ExampleApplication.class);
          ConfigurableApplicationContext context = app.run(args);
  
          environment = context.getEnvironment();  //compile error
          buildProperties = context.getBean(BuildProperties.class); //compile error
  
      DisplaySysInfo displaySysInfo = new DisplaySysInfo(environment, buildProperties, log);
      displaySysInfo.splash();
  
      }
  
  }
  </code></pre>