According to EJB3 DI documentation it is possible to inject fields and setters. But how to inject a bean constructor ?
How to dependecy inject an EJB3 constructor?
what do you mean with " to inject a bean constructor"? –
Handclap
A bean is a class a class has a constructor. To be more testable to class must accept its dependencies via its constructor. Can EJB resolve classes dependencies like Guice and Spring DI does ? –
Tremml
The EJB specification does not support constructor injection. The EJB programming model only uses the no-arg constructor, and can then perform field or setter method injection after the instance has been constructed.
That said, EJB 3.1 is part of EE 6, which includes CDI. If your EJB module is a CDI BDA (bean deployment archive) because it includes beans.xml, then you can use CDI constructor injection.
Aha I got it. But being not able to inject the constructor is very bad design ! –
Tremml
If your design requires constructor injection, then you can use CDI. If this answered your question, please accept. –
Claudication
© 2022 - 2024 — McMap. All rights reserved.