1. @Test
    2. public void test7() {
    3. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("xmls/BeanFour.xml");
    4. School school = context.getBean("schoolShow",School.class);
    5. System.out.println("第四步——对象的创建");
    6. System.out.println(school);
    7. context.close();
    8. }

    bean

    1. package com.zcc.spring.pojo;
    2. public class School {
    3. private String typeId;
    4. private String classroom;
    5. public School() {
    6. System.out.println("第一步——构造地的调用");
    7. }
    8. public School(String typeId, String classroom) {
    9. this.typeId = typeId;
    10. this.classroom = classroom;
    11. }
    12. public void setTypeId(String typeId) {
    13. System.out.println("第二步——set对象的调用");
    14. this.typeId = typeId;
    15. }
    16. public void setClassroom(String classroom) {
    17. this.classroom = classroom;
    18. }
    19. public void initMethod() {
    20. System.out.println("第三步——初始化initMethod方法的调用");
    21. }
    22. public void destroyMethod() {
    23. System.out.println("第五步——执行destroyMethod销毁方法");
    24. }
    25. }

    xml的

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    5. <bean id="schoolShow" class="com.zcc.spring.pojo.School" init-method="initMethod" destroy-method="destroyMethod">
    6. <property name="typeId" value="软件技术"/>
    7. <property name="classroom" value="软件技术3班"/>
    8. </bean>
    9. </beans>