Java
  Home arrow Java arrow Page 3 - The Spring Framework: Understanding IoC
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
JAVA

The Spring Framework: Understanding IoC
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 15
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek