@Test
public void test7() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("xmls/BeanFour.xml");
School school = context.getBean("schoolShow",School.class);
System.out.println("第四步——对象的创建");
System.out.println(school);
context.close();
}
bean
package com.zcc.spring.pojo;
public class School {
private String typeId;
private String classroom;
public School() {
System.out.println("第一步——构造地的调用");
}
public School(String typeId, String classroom) {
this.typeId = typeId;
this.classroom = classroom;
}
public void setTypeId(String typeId) {
System.out.println("第二步——set对象的调用");
this.typeId = typeId;
}
public void setClassroom(String classroom) {
this.classroom = classroom;
}
public void initMethod() {
System.out.println("第三步——初始化initMethod方法的调用");
}
public void destroyMethod() {
System.out.println("第五步——执行destroyMethod销毁方法");
}
}
xml的
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="schoolShow" class="com.zcc.spring.pojo.School" init-method="initMethod" destroy-method="destroyMethod">
<property name="typeId" value="软件技术"/>
<property name="classroom" value="软件技术3班"/>
</bean>
</beans>