JavaFX: Instantiate Application within Spring Context
JavaFX application is typically instantiated via calling static method launch(…) on object inherited from Application:
But this hardly fits into IoC solution - in this case Spring Context. I was trying to find suitable solutions but failed. There is no simple way how to instantiate Application in dynamic way.
Fortunatelly there is workaround: Start application in static way, in start(…) method save created Application instance into static variable and then create Spring context. Instance of Application is accessible through static method.
So something like:
With following in beans.xml:
Then “app” behaves as plain bean and you can use it as such.