Featured Post

Spring Framework Dependency Injection

Hi There,


Dependency Injection in Spring framework is a savvy logic implemented by spring.org . Once you understand this dependency injection It is very easy to understand the Spring core and entire framwork .
Dependency Injection is nothing But Inversion of Control .
Lets assume in Normal java we have One class and it has  more member variables .
In that case we need to   set all the properties in Constructor with default values .
and also need to implement setters and getters . So every time you need to call those setters and getters in your Existing logic in order to get or set values . But Spring framework has been designed in such a way that  There is a BeanFactory which will be taking care of all this things at a time . And also application context has been deployed here in the same passion only.
Gotcha..! now you Got the logic I guess . so here Need to mention  everything in the Spring .xml file only .
If you are using  ApplicationContext then need to use FileSystemApplicationContext to  parse the xml .


Here we have two types of Dependency Injections .
1)setter based injection
2)constructor based injection

So   first logic is already being explained above . second logic is same as constructor calling with corresponding parameters .

For setter Injection xml file would be as followes
---------------------------------------------------------------------------------

 
    
       ---/value>
    
-------------------
-----------------


         
For constructor based Injection
--------------------------------------------------

 
             
  





Thanks
Venkat

Comments