1.

What are setter injection and constructor injection in spring?

Answer»

Setter Injection is a type of dependency injection (DI) in which the framework uses a setter METHOD to inject dependent objects into the client. The CONTAINER first calls the no-argument constructor and later it calls the setters. Such setter-based injections can work even if dependencies are injected using the constructor.

Constructor injection uses a constructor for injecting dependencies on Spring-managed BEANS. The constructor DI is achieved when the container initiates a CLASS constructor with arguments, each argument REPRESENTING dependencies on other classes.



Discussion

No Comment Found