Dependency Injection

In Spring framework, Dependency Injection (DI) is nothing but a design pattern which is used to define the object dependencies between each other that means removes dependencies arises in code. It makes our programming code loosely coupled. There are two ways provided by Spring framework to inject dependencies, such as :

  • Setter Injection
  • Constructor Injection


  •  

dependency_injection

Setter Injection

This is the most popular and simple Dependency Injection method. In this injection, the spring container uses setter method in the dependent class for injecting its dependencies. Spring container perform setter injection by reading the information from an external file called spring configuration file. In spring each class is known as spring bean, this bean is no way related with the java bean Spring bean and java bean both are not same because a java bean needs definitely a public default constructor but in spring bean, some time we include default constructor or sometimes we do not.

Constructor Injection

This is another dependency injection method .Here in this type of injection constructor of bean class is used by the container. In configration file, we have to use to inform the IOC container. If both constructor and setter injection applied for same properly in bean class then constructor injection will be overriden by setter injection

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology, BBSR
Call to: 0674-2361252

Comment