Spring ClassPathResource Demo : ClassPathResource « Spring « Java






Spring ClassPathResource Demo

       
File: hello.xml

<?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="helloimpl">
   <property name="greeting">
       <value>Good Morning!...</value>
   </property>
   </bean>
</beans>


File: helloclient.java

import java.io.*;

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

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

    {
        try
        {
        System.out.println("point1");

        Resource  res = new ClassPathResource("hello.xml");
        System.out.println("point2");

        BeanFactory  factory = new XmlBeanFactory(res);
        System.out.println("point3");

        hello bean1 = (hello)factory.getBean("hello");

        String s = bean1.sayhello("Joe");

        System.out.println(s);

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


File: helloimpl.java

public class helloimpl implements hello
{
      private String greeting;

      public helloimpl()
      {
      }
      public helloimpl(String a)
      {
          greeting=a;
      } 
      public String sayhello(String s)
      {
           return greeting+s;
      }
      public void setGreeting(String a)
      {
           greeting=a;
      }

}


File: hello.java

public interface hello
{
      public String sayhello(String a);
}



           
       








Spring-SpringClassPathResourceDemo.zip( 1,480 k)

Related examples in the same category