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:

best Books for Spring
Learning Spring Application Development(3.75 l 5) navven
Introducing Spring Framework(3.75 l 5) by exmple
Learn Java for Web Developmen(3.25 l 5) GOOD
Nicholas S. Williams - Professional Java for Web Applications(3 l 5) ok