文档:
包下载的位置
1.pom如下:
1 23 7org.springframework 4spring-core 55.0.9.RELEASE 68 12 13org.springframework 9spring-context 105.0.9.RELEASE 1114 18 19org.springframework 15spring-beans 165.0.9.RELEASE 1720 org.springframework 21spring-expression 225.0.9.RELEASE 23
2.建立User类
1 public class User { 2 private String name; 3 private Integer age; 4 5 public String getName() { 6 return name; 7 } 8 9 public void setName(String name) {10 this.name = name;11 }12 13 public Integer getAge() {14 return age;15 }16 17 public void setAge(Integer age) {18 this.age = age;19 }20 }
3.xml配置
1 26 7 8 9 10 1112 13 14 15 16 17
4.实例化User类
main方法里:
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
1 //位置:setting/applicationContext.xml2 ApplicationContext context = new ClassPathXmlApplicationContext("setting/applicationContext.xml");3 User user = context.getBean("user",User.class);4 System.out.println(user);