Spring3: How to set up dependency jars for basic IoC function

阅读更多

1. Import relevant jars for basic IoC purpose

        1) Download spring-framework-3.2.2.RELEASE-dist.zip from http://www.springsource.org/download/community

        2) Open eclipse and set up user library

        3) Import relevant jars including:

            (1) spring-core-3.2.2.RELEASE.jar

            (2) spring-beans-3.2.2.RELEASE.jar

            (3) spring-expression-3.2.2.RELEASE.jar

            (4) spring-context-3.2.2.RELEASE.jar

        4) Download commons-logging-1.1.2-bin.zip from http://commons.apache.org/proper/commons-logging/download_logging.cgi

        5) Import relevant jars including:

            (1) commons-logging-1.1.2.jar

 

2. Create new java project and import user library created before. And import JUnit4 lib for unit test.

3. Start coding:

        1) beans.xml [In the root directory of src folder]

 




  
    
    
    
    
  

         2) POJO

package edu.xmu.domain;

public class Student {
	private Integer id;
	private String name;
	private Integer age;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
}

         3) Test case

package edu.xmu.domain;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class StudentTest
{

	@Test
	public void test()
	{
		ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");

		Student student = (Student) ac.getBean("student");

		System.out.println("Student info: ");
		System.out.println("ID: " + student.getId() + ", Name: "
				+ student.getName() + ", Age: " + student.getAge());
	}

}

你可能感兴趣的:(Spring,IoC,jars,import)