Types of Dependency Injection

In Spring, providing the values for the properties of a bean (i.e values to its member variables) is known as property injection. The properties of a bean are known as its dependencies. So it is also known as Dependency Injection.You may know that in Spring it is the responsibilty of the container to inject the dependencies into a  bean when it creates the bean. This is also known as Inverse of Control (IOC).

Dependency Injection can be categorized into three categories :

1) Constructor injection
2) Setter Injection
3) Interface Injection

Spring supports only constructor and setter injection.

In Constructor injection values are injected using constructors of a bean and <constructor-arg> tags while in Setter injection  values are injected using setter methods of a bean and <property> tags.

Click on the links above to know more about constructor and setter dependency injection.

I would like to know your comments and if you liked the article then please share it on social networking buttons.

No comments:

Post a Comment