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

Beans and Client - 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

Next is the beans.xml file. It contains configuration information for the POJO and its properties.


<beans>

<bean id=”SimpleInterestBean”

class=”org.me.SimpleInterestCalculatorBean”>

<property name=”principle”>

<value>10000.00<value>

</property>

<property name=”years”>

<value>10.00<value>

</property>

<property name=”rate”>

<value>9.50<value>

</property>


</bean>

<beans>


Last is the code for Client.java. It first loads the configuration, then gets a reference for BeanFactory and retrieves the instance of SimpleInterestCalculatorBean. After that, it calls the calculate method to get the calculated simple interest. Here is the code:


import java.io.*;

import org.springframework.beans.factory.*;

import org.springframework.beans.factory.xml.*;

import org.springframework.core.io.*;


public class Client


{


public static void main(String args[]) throws Exception


{


try


{


System.out.println("please Wait.");

Resource res = new ClassPathResource("beans.xml");

BeanFactory factory = new XmlBeanFactory(res);

SimpleInterestCalculatorBean interest=

(SimpleInterestCalculatorBean)factory.getBean(“SimpleInterestBean);

System.out.println(interest.getInterest());

}


catch(Exception e1)


{ System.out.println(""+e1); }


}


}


That completes the introduction to Spring Framework. What has been described here is just the tip of the iceberg. In the future, I will be discussing each of the components of Spring Framework in depth. Till then…



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