Spring Tutorial

Introduction

For Developing Spring application we need

  • Bean Class
  • Driver Class    --> Contains BeanFactory to create objects
  • spring.xml
HelloWorld Example
------------------------------------
package bean;

public class Bean {

public Bean() {
System.out.println("Constor - PROTOTYPE TEST");
}

public void Hello(){

System.out.println("Hello Spring");
}

}
------------------------------------------------------------------------
package driver;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import bean.Bean;

public class Driver {

public static void main(String[] args) {
// TODO Auto-generated method stub

Resource res = new ClassPathResource("res/spring.xml");
BeanFactory f = new XmlBeanFactory(res);
Bean ob =(Bean)f.getBean("t");
ob.Hello();


}

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

<beans>  
   <bean id="t" class="bean.Bean">  </bean>  
</beans>
-----------------------------------------------------------------------------------


IoC


1 Comments

Thank You

Previous Post Next Post