You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try to inject spring beans in a presenter, using this code:
val view:AfterburnerView=AfterburnerView({ name -> context.getBean(name) })
And works fine until I use HelloUserService interface instead of HelloUserServiceImpl. This stacktrace appears after crash:
Caused by: java.lang.IllegalStateException: Cannot instantiate view: interface com.github.goto1134.fxframeworks.HelloUserService
at com.airhacks.afterburner.injection.Injector.lambda$getDefaultInstanceSupplier$9(Injector.java:228)
at com.airhacks.afterburner.injection.Injector.instantiateModelOrService(Injector.java:111)
at com.airhacks.afterburner.injection.Injector.injectMembers(Injector.java:144)
at com.airhacks.afterburner.injection.Injector.injectMembers(Injector.java:129)
at com.airhacks.afterburner.injection.Injector.injectAndInitialize(Injector.java:122)
at com.airhacks.afterburner.injection.Injector.registerExistingAndInject(Injector.java:103)
at com.airhacks.afterburner.injection.Injector.instantiatePresenter(Injector.java:56)
at com.airhacks.afterburner.views.FXMLView.lambda$loadSynchronously$1(FXMLView.java:85)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:929)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 15 more
Caused by: java.lang.InstantiationException: com.github.goto1134.fxframeworks.HelloUserService
at java.lang.Class.newInstance(Class.java:427)
at com.airhacks.afterburner.injection.Injector.lambda$getDefaultInstanceSupplier$9(Injector.java:226)
... 28 more
Caused by: java.lang.NoSuchMethodException: com.github.goto1134.fxframeworks.HelloUserService.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 29 more
Problem
The problem is in the logic of initialization with its injection and postinjection steps, where on regular injection step the Injector creates an object for the class of the parameter.
My vision of solution
The situation when you create and inject object which already exists and should be injected on postinjection step is incorrect and should be fixed. Also doing injection this way may cause unpredictable behaviour in some (bad designed) applications.
Moreover, I don't see any reason to use two-step injection. If an object exists in injectionContext, it should be injected on the only injection step immediately.
Correct me if I'm wrong.
The text was updated successfully, but these errors were encountered:
tobiasdiez
added a commit
to tobiasdiez/afterburner.fx
that referenced
this issue
Oct 22, 2017
The example can be taken from goto1134/javafx-frameworks-comparation#afterburner-failing-injection branch.
Description
My presenter class:
I try to inject spring beans in a presenter, using this code:
And works fine until I use
HelloUserService
interface instead ofHelloUserServiceImpl
. This stacktrace appears after crash:Problem
The problem is in the logic of initialization with its injection and postinjection steps, where on regular injection step the Injector creates an object for the class of the parameter.
My vision of solution
The situation when you create and inject object which already exists and should be injected on postinjection step is incorrect and should be fixed. Also doing injection this way may cause unpredictable behaviour in some (bad designed) applications.
Moreover, I don't see any reason to use two-step injection. If an object exists in
injectionContext
, it should be injected on the only injection step immediately.Correct me if I'm wrong.
The text was updated successfully, but these errors were encountered: