Source Code : Spring ClassPathResource Demo

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

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);
}



           
       

Thank with us