Suppose that I have Spring service classes or JSF beans. I wire these classes in another class. There are no problems till now. I can use these injected fields in any method.
But, using them in the constructor gives me a NullPointerException.
Probably the constructor runs before dependency injection happens, and it doesn’t see my injected fields. Is there any solution to use dependency injection in a constructor?
Obviously, it’s not possible to inject anything in an object if this object doesn’t exist. And to exist, an object must be constructed.
Spring supports constructor injection:
Spring also supports @PostConstruct, which allows initializing a bean after all the dependencies have been injected.
Don’t know about JSF.