Spring Dependency Injection
Join the DZone community and get the full member experience.Join For Free
spring di is the most fundamental feature that spring provides. this feature has also been referred as inversion of control but after many discussions it was decided that di is a better term.
any application which is of practical use is composed of two or more objects which communicate with, or use, each other. traditionally each of those objects is responsible to get the reference of objects it uses but in di objects are given references to the other objects when needed. all the bean creation and their injection are handled by spring which acts as a container of beans. this provides loose coupling and also promotes programming to an interface as the bean knows only about the type of bean but nothing about its implementation.
for example : if the bean store has declared product property as an interface then the product implementation becomes irrelevant. the product bean can be web-service implementation, an ejb or a mock test object.
some other benefits of using di:
• reduction of boiler plate coding.
• as all metadata is in xml file and is easy to configure. this gives flexibility in testing and development.
Opinions expressed by DZone contributors are their own.