title: Spring in a JavaFX application - how to property handle controller as dependency?
body: <p>I have a JavaFX application that uses spring boot, exactly as described in this blog post:</p>
  
  <p><a href="http://www.greggbolinger.com/let-spring-be-your-javafx-controller-factory/" rel="nofollow noreferrer">http://www.greggbolinger.com/let-spring-be-your-javafx-controller-factory/</a></p>
  
  <p>I am using the FXML loader overriding the controller factory to use spring.</p>
  
  <p>The problem is that Spring loads the controller class marked as @Component on application start or later if marked with @Lazy, but keeps the bean in memory.</p>
  
  <p>If I open a Stage, modify the data, close the stage and open it again, the data is still there (because the controller was kept by spring). It also gets in the way if I open two of the same Stage (window). It shares the same controller, so if I modify one, the other modifies too, and this is not the desired behavior.</p>
  
  <p>How to I properly handle JavaFX controllers with spring?</p>
  
  <p>Thanks!</p>