Home arrow Java & J2EE arrow Page 2 - Introducing the Spring Framework

Using Spring Framework, Step by Step - Java

In this discussion, I will be focusing on the Spring Framework. The first section will be about the whys and wherefores of the Spring Framework. In the second and third sections, I will explain how to use the Spring Framework to implement business logic. In the fourth and fifth sections, I will develop an application that uses the Spring Framework.

TABLE OF CONTENTS:
  1. Introducing the Spring Framework
  2. Using Spring Framework, Step by Step
  3. Mapping the Beans continued
  4. Spring Framework in the Real World
  5. Beans and Client
By: A.P.Rajshekhar
Rating: starstarstarstarstar / 113
March 05, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

To use the Spring Framework in an application, there are three main steps. They are:

  1. Developing the POJO

  2. Mapping the POJO

  3. Developing the Client

The second step involves an XML file that the Spring Framework uses to understand the configuration. These are the details:

Developing the POJO: POJO or Plain Old Java Objects are, essentially, simple JavaBeans. The first step in using the Spring Framework is to wrap the business logic in a JavaBean. For example, if the logic just says hello, the bean will be as follows:

public class Hello


{


private String greeting;

public Hello()


{


}


public Hello(String a)


{


greeting=a;


}


public String sayhello(String s)


{


return greeting+s;


}


public void setGreeting(String a)


{


greeting=a;


}


}


It is a simple JavaBean with getters and setters. That completes the first step.

Mapping the Beans: The beans need to be mapped using XML so that the IoC container can ‘inject’ the required dependency at runtime. The configuration file contains the following entries. They are:

  • beans
  • bean
  • property
  • value

These are the most common entries. They are arranged in a hierarchical manner. Here are the details:

Beans is the first entry or tag. It is the root tag/element of the configuration file. It encapsulates the bean tags.

The details of the bean are given to the Spring Framework. The details are passed using the attributes of the bean tag. The most commonly used attributes are:

  • id – id by which the bean will be called. It has to be unique.
  • class – the fully qualified name of the bean.

For example, to provide the details for the Hello bean, the bean tag will be as follows:


<beans>

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

:

:

</bean>

<beans>



 
 
>>> 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: