Home arrow Java & J2EE arrow Page 3 - The Spring Framework: Understanding IoC

Injections - Java

IoC or Inversion of Control is one of the core features of Spring. It helps in simplifying the implementation of business logic. To use the Spring Framework to its full potential, understanding the IoC container of the framework is essential. Hence, in this discussion, the focus will be on the IoC – the concept as well as the container provided by Spring Framework.

TABLE OF CONTENTS:
  1. The Spring Framework: Understanding IoC
  2. Spring Framework and Forms of IoC: Implementation
  3. Injections
  4. Spring Framework in the Real World
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 62
May 14, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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 & J2EE Articles          >>> More By A.P.Rajshekhar
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: