首先目录结构如下:
1. User.java
1 package cn.sxt.vo; 2 3 import java.util.Date; 4 5 public class User { 6 7 private String name; 8 private int age; 9 private Date birthday;10 public String getName() {11 return name;12 }13 public void setName(String name) {14 this.name = name;15 }16 public int getAge() {17 return age;18 }19 public void setAge(int age) {20 this.age = age;21 }22 public Date getBirthday() {23 return birthday;24 }25 public void setBirthday(Date birthday) {26 this.birthday = birthday;27 }28 @Override29 public String toString() {30 return "User [name=" + name + ", age=" + age + ", birthday=" + birthday + "]";31 }32 }
2. beans.xml
3. context.xml
描述信息
4. SpringTest.java
package cn.sxt.spring;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.sxt.vo.User;public class SpringTest { @Test public void testHello(){ ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml"); User u=(User)ac.getBean("u4"); System.out.println(u); }}