Download Spring 3.1 from here.
Once you extract, create a user library named Spring3 and include all the jars from spring-framework-3.1.0.M2\dist directory. Add one more jar(commons-logging.jar) that you can find in spring-framework-3.1.0.M2\projects\spring-build\lib\ivy directory.

Create 2 classes as follows.
package com.test;
public class HelloWorld {
public void printHello(){
System.out.println("Hello Spring 3.0!");
}
}
And
package com.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloWorldTest {
public static void main(String[] args) {
//XmlBeanFactory ctx = new XmlBeanFactory(new ClassPathResource("hello.xml")); //Deprecated Approach
ApplicationContext ctx = new ClassPathXmlApplicationContext("hello.xml");
HelloWorld hw = (HelloWorld) ctx.getBean("HelloBean");
hw.printHello();
}
}
Now, create an xml file hello.xml in src directory.

That's it.
Output:

Once you extract, create a user library named Spring3 and include all the jars from spring-framework-3.1.0.M2\dist directory. Add one more jar(commons-logging.jar) that you can find in spring-framework-3.1.0.M2\projects\spring-build\lib\ivy directory.
Create 2 classes as follows.
package com.test;
public class HelloWorld {
public void printHello(){
System.out.println("Hello Spring 3.0!");
}
}
And
package com.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloWorldTest {
public static void main(String[] args) {
//XmlBeanFactory ctx = new XmlBeanFactory(new ClassPathResource("hello.xml")); //Deprecated Approach
ApplicationContext ctx = new ClassPathXmlApplicationContext("hello.xml");
HelloWorld hw = (HelloWorld) ctx.getBean("HelloBean");
hw.printHello();
}
}
Now, create an xml file hello.xml in src directory.
That's it.
Output:
No comments:
Post a Comment