title: How to get ApplicationContext in main function - Spring boot
body: <p>I want to combine two libraries - JavaFx and Spring Boot, thus I need to have an instance of <code>ApplicationContext</code> in my start() method in main class:</p>
  
  <p>Main class:</p>
  
  <pre><code>@SpringBootApplication
  public class JavaFXandSpringBootTestApplication extends Application{
  
      @Autowired
      ApplicationContext ctx;
  
      public static void main(String[] args) {
          SpringApplication.run(JavaFXandSpringBootTestApplication.class, args);
          launch();
      }
  
      @Override
      public void start(Stage stage) throws Exception {
          FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/LogIn.fxml"));
          loader.setController(ctx.getBean(LogInController.class)); // HERE OCCURES ERROR
          Scene scene = new Scene((Parent)loader.load());
          stage.setScene(scene);
          stage.show();
  
      }
  
  }
  </code></pre>
  
  <p>Controller class:</p>
  
  <pre><code>@Component
  public class LogInController {
  
  }
  </code></pre>
  
  <p>As I have read the documentary <code>@SpringBootApplication</code> enables auto detect of Components and under the hood is also annotating the class with <code>@Configuration</code>.
  So now, why am i reciving a NullPointerException in commended line? It's because that ctx isn't injected properly, but why? What am i doing wrong?</p>