Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Dependency Injection

DZone's Guide to

Spring Dependency Injection

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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.

 

From http://himanshugpt.wordpress.com/2010/07/05/spring-dependency-injection/

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}