Getting acknowledged with "Spring boot + JavaFX" coop.
Was hoping to get answers for such questions:
- In the examples through out the web I've found only cases of "@SpringBootApplication" set to the "... extends Application" and by this overriding the "init()" method. But is there a way to have the initial annotation in another place and mark the "Application" bean as a component, thus starting it manually?
I'm not that good with 'JavaFX' yet, and I've tried to start that bean by calling the 'Application.start(UIClass.class)' and got no spring functionality(I get the idea that this doesn't start the object bean, but initiates it separately).
- How to properly initiate a spring app from even the 'extends Application'? The examples I've found suggest to override the 'init()' and place the 'ApplicationContext' there. This works, but didn't manage to use the autowiring and similar stuff(and I did verify that the bindings work and have the appropriate naming).
In a similar thread (Spring Boot Main and JavaFX) I've found a solution to use the:
ApplicationContext ctx = SpringApplication.run(Root.class);
ctx.getAutowireCapableBeanFactory().autowireBean(this);
but I have the feeling that this is more of a workaround and I've made a mistake somewhere.
Thanks in advance.
Applicationclass (which is, as you've observed, instantiated for you when the application is launched) is the entry point for a JavaFX application, and really should do little more than manage the application lifecycle. So it's really the natural class to annotate with@SpringBootApplicationanyway. If you need access to theApplicationinstance anywhere else, you basically have your JavaFX application structured incorrectly.Applicationinstance using the code block you have at the end; but in a real application you won't need this because you won't need theApplicationinstance anywhere else in the application anyway...