Spring

 
 
This peice of code will direct you how spring works in basic.
 
 
  1. //Interface

  2. public  interface  rmservice

  3. {

  4.     String     getresult(String    s);

  5. }

  6.  

  7. //Interface Implmentation

  8. public class rmserviceimpl  implements    rmservice

  9. {

  10.         private String greeting ;

  11.  

  12.    public rmserviceimpl()

  13.    {

  14.       System.out.println("constructor ok");

  15.    }

  16.  

  17.    public String getresult(String  a)

  18.    {

  19.       return "Hai " this.greeting a;

  20.    }

  21.  

  22.   public void setGreeting(String a)

  23.       {

  24.            greeting=a;

  25.       }

  26.        

  27. }

  28.  

  29. //rmservice.xml

  30. <?xml version="1.0" encoding="UTF-8"?>

  31.  

  32. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"  "http://www.springframework.org/dtd/  spring-beans.dtd">

  33.  

  34.   <beans>

  35.  

  36.    <bean id="rmservice" class="rmserviceimpl">

  37.         <property name="greeting">

  38.                <value>Good Morning!...</value>

  39.         </property>

  40.    </bean>

  41. </beans>

  42.  

  43. //Client

  44. import java.io.*;

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

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

  47. import org.springframework.core.io.*;

  48.  

  49. public class   rmserviceclient

  50. {

  51.    public static void main(String args[])

  52.    {

  53.       try

  54.       {

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

  56.          Resource  res = new ClassPathResource("rmservice.xml");

  57.          BeanFactory  factory = new  XmlBeanFactory(res);

  58.          System.out.println("factory created");

  59.          rmservice bean1 = (rmservice)factory.getBean("rmservice");

  60.          String s = bean1.getresult(args[0]);

  61.          System.out.println(s);

  62.       }

  63.  

  64.         catch(Exception e1)

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

  66.    }

  67.  

  68. } 
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 16th Jun 2008
  Rating : No Rating
  Accessed  :  8485
  Submitted by :  asdave
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related Java Source Codes
  • Wraps a string to a given number of characters using a string break character
  • Uppercase the first character of each word in a string
  • Make a string's first character uppercase
  • Strip whitespace (or other characters) from the beginning and end of a string
  • Return part of a string

  • Copyright © 2013 VisualBuilder. All rights reserved