View RSS Feed

Spring Framework

Spring Dependency Injection

Rate this Entry
by , 07-07-2012 at 06:33 PM (867 Views)
Java classes and components shall not be dependent upon any other java classes. It could be increasing the possibilities of reusage of such classes and they could be tested independently. For decoupling of the java components, there is a need to inject some dependency of various other classes’ persent.

Class A is dependent upon Class B in case Class B is used as variable.

When dependency injection is being used, in that case Class B would be given to A through:

• constructor of class A. This is known as construction injection
• A setter. This is known as setter injection

General concept present b/w the dependency injection is well known as inversion of control. Class shall not be configuring itself. It shall be configured from somewhere outside.

Design which is based at independent components or classes would be increasing the testing possibility and re-usability of the software. Let us say for instance, when Class A is expecting Data Access Object to receive the information ftom database then you can create other test object easily that would be mocking the connection of database and would be injecting object into A so that A could be tested withour using actual connection of the database.
Software design that is based at the injection of dependency is possible with the standardized java.

Submit "Spring Dependency Injection" to Facebook Submit "Spring Dependency Injection" to Digg Submit "Spring Dependency Injection" to Submit "Spring Dependency Injection" to StumbleUpon Submit "Spring Dependency Injection" to Google