Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-26-2007, 10:32 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
A Sample spring Application
For a sample application of spring copy following jar file in your class path settings

1. spring.jar from spring12\dist folder
2. commons-logging.jar from tomcat41\server\lib folder

Now we will make following files

1. An interface that defines the functions.
2. An Implementation of Interface containing properties, its setter and getter methods, functions etc.
3. A XML file called Spring configuration file.
4. Client program to use the function.


Here is the interface SayHello

Code:
public interface SayHello { public String Helloworld(String a); }
Here is implementation class SayHelloImpl

Code:
public class SayHelloImpl implements SayHello { private String greeting ; public SayHelloImpl () { } public SayHelloImpl(String a) { greeting=a; } public String sayHelloImpl(String s) { return greeting+s; } public void setGreeting(String a) { greeting=a; } }
Here is XML Configuration File

Code:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" " http://www.springframework.org/dtd/spring-beans.dtd "> <beans> <bean id="hello" class="SayHelloImpl"> <property name="greeting"> <value>Good Morning.</value> </property> </bean> </beans>
Here is Client Program

Code:
import java.io.*; import org.springframework.beans.factory.* ; import org.springframework.beans.factory.xml.*; import org.springframework.core.io.*; public class SayHelloClient { public static void main(String args[]) throws Exception { try { System.out.println("please Wait."); Resource res = new ClassPathResource(" hello.xml"); BeanFactory factory = new XmlBeanFactory(res); sayhello bean1 = (sayhello)factory.getBean("hello"); String s = bean1.sayHello(args[0]); System.out.println(s); } catch(Exception e1) { System.out.println(""+e1); } } }
Now run the program

Suppose you have all files in springdemo directory

Code:
f:\springdemo>javac say*.java f:\springdemo>javac helloimpl.java f:\springdemo>javac helloclient.java f:\springdemo>java helloclient "sam"
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sample Spring Application Java Tip Java Tips 0 03-29-2008 02:41 PM
Sample ANT Script Java Tip Java Tips 0 01-24-2008 05:22 PM
Sample Session Beans Java Tip Java Tips 0 12-29-2007 06:53 PM
Sample Entity Bean Java Tip Java Tips 0 12-28-2007 12:41 PM
java Sample 77 3 when using Eclipse Albert Eclipse 1 07-05-2007 08:47 AM


All times are GMT +3. The time now is 01:30 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org