JavaFX and Spring: issue with autowiring
<p>I am trying to use JavaFX and Spring together. I am using Spring Boot, in particular.
My issue is that I have both Spring autowired fields and JavaFX "autowired" fields in the FXML controller.
I put a breakpoint in the constructor controller and it is actually being invoked twice: one by Spring, which autowires <code>@Autowired</code> fields only, one by JavaFX, which initialize <code>@FXML</code> fields only.</p>

<p>Here's my main code:</p>

<pre><code>@SpringBootApplication
public class MySpringAndJavaFXApp extends AbstractJavaFXAndSpringApplication {

    @Override
    public void start(Stage window) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/home.fxml"));
        window.setTitle("My Title");
        window.setScene(new Scene(root, 500, 300));
        window.show();
    }


    public static void main(String[] args) {
       launchApp(MySpringAndJavaFXApp.class, args);
    }
}
</code></pre>

<p>Here's the class I am extending:</p>

<pre><code>public abstract class JavaFXAndSpringApplication extends Application {

    protected static void launchApp(Class&lt;? extends JavaFXAndSpringApplication&gt; classePrincipaleJavaFX, String[] args) {
        launch(classePrincipaleJavaFX,args);
    }

    private ConfigurableApplicationContext applicationContext;

    @Override
    public void init() throws Exception {
        applicationContext = SpringApplication.run(getClass());
        applicationContext.getAutowireCapableBeanFactory().autowireBean(this);
    }

    @Override
    public void stop() throws Exception {
        super.stop();
        applicationContext.close();
    }
}
</code></pre>

<p>An example of a class being Spring-managed and JavaFX-managed:</p>

<pre><code>@Component
public class MixedController {

    @FXML
    private TextField aTextField;

    @Autowired
    private MyService myService; // MyService is a @Component


    public MixedController() {
        System.out.println("I am here"); // debugger goes twice here
    }
}
</code></pre>

<p>How I can easily fix my issue?
I attempted using a custom FXML loader (e.g. <a href="https://stackoverflow.com/questions/32424878/javafx-and-spring-beans-doesnt-autowire">JavaFX and Spring - beans doesn&#39;t Autowire</a>). However, if I load the home.fxml file with such loader, I get an error on the data provider (i.e. Spring is not getting my database configuration correctly) and I would prefer another approach.</p>