<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="d1" class="com.dto.Teacher" scope="singleton">
<property name="id" value="1"></property>
<property name="name" value="永强"></property>
<property name="sex" value="男"></property>
<property name="age" value="20"></property>
</bean>
<bean id="d2" class="com.dto.Clazz" scope="prototype">
<property name="cid" value="1"></property>
<property name="cname" value="A"></property>
</bean>
</beans>
package com.dto;
public class Clazz {
private Integer cid;
private String cname;
public Clazz() {
super();
// TODO Auto-generated constructor stub
}
public Clazz(Integer cid, String cname) {
super();
this.cid = cid;
this.cname = cname;
}
@Override
public String toString() {
return "Clazz [cid=" + cid + ", cname=" + cname + "]";
}
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
}
package com.dto;
public class Teacher {
private Integer id;
private String name;
private String sex;
private Integer age;
public Teacher() {
super();
// TODO Auto-generated constructor stub
}
public Teacher(Integer id, String name, String sex, Integer age) {
super();
this.id = id;
this.name = name;
this.sex = sex;
this.age = age;
}
@Override
public String toString() {
return "Teacher [id=" + id + ", name=" + name + ", sex=" + sex
+ ", age=" + 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 String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
package com.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.dto.Clazz;
import com.dto.Teacher;
public class Test {
public static void main(String[] args) {
//获取对象
ApplicationContext a = new ClassPathXmlApplicationContext("applicationContext.xml");
Teacher d1 = (Teacher) a.getBean("d1");
System.out.println(d1);
Clazz d2 = (Clazz) a.getBean("d2");
System.out.println(d2);
}
}
There is no solace above or below. Only us… Small, solitary, battling one another. I pray to myself, for myself.
天堂地狱都没法给你慰藉,只有我们自己:渺小,孤独,奋斗,与彼此抗争。我向自己祈祷,为自己祈祷。