Java
  Home arrow Java arrow Page 3 - The Spring Framework: Understanding Io...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

The Spring Framework: Understanding IoC
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-05-14

    Table of Contents:
  • The Spring Framework: Understanding IoC
  • Spring Framework and Forms of IoC: Implementation
  • Injections
  • Spring Framework in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Spring Framework: Understanding IoC - Injections


    (Page 3 of 4 )


    The Setter Injection is the most commonly used form of Dependency Injection in the Spring Framework. To tell Spring that the application wants to use a Setter Injection, the declaration needs to be made in the configuration file. Just as with Constructor Injection, the declaration is done in the beans section. The steps involve declaring the properties of the POJO and passing the value to the property. 

    The properties of a POJO are its instance variables. To declare the attributes, the <property> element is used. This element is the child element of the <bean> element. The value of the name attribute of <property> accepts the name of a property of the POJO declared using the <bean> element. For example, to declare the userName property of the GreetingBean, the code would be:


    <bean id=”GreetingBean” class=”org.me.GreetingBean”>

    <property name=”username”>

    :

    :

    </property>

    </bean>

     

    To pass the desired value to the property, the <value> element needs to be used. It is the child element of <property>. For example, to pass the value “Raj” to the property userName, the code would be:

    <bean id=”GreetingBean” class=”org.me.GreetingBean”>

     <property name=”username”>

    <value>Raj</value>

    </property>

    </bean>

     

    That’s how Setter Injection is used in Spring Framework.

    Finally, the Spring Framework does not support Interface Injection. However, using an auto-wiring service, one can make use of Interface Injection. How to use it will be discussed in the future, when I cover auto-wiring in detail.

    That completes this section. In the next section will look at an application that will make use of Constructor Injection.

    More Java Articles
    More By A.P.Rajshekhar


       · Thanks for providing good article for understading basics of Spring IOC
       · Great article. I can't wait for the next one...Just a few questions. The...
     

       

    JAVA ARTICLES

    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT