- 执行无参构造器,创建了bean实例
- 调用了set方法,设置了属性值
- 执行了初始化的方法
- 获得了创建bean实例对象
- 执行了销毁的容器的方法
| package com.guodaxia.bean.lifttime; |
| |
| public class TestTime { |
| |
| String name; |
| public TestTime() { |
| System.out.println("执行第一步,无参构造"); |
| } |
| |
| public void setName(String name) { |
| this.name = name; |
| System.out.println("执行第二步,set方法"); |
| } |
| |
| public void initMethod(){ |
| System.out.println("执行第三步,初始化的方法"); |
| } |
| |
| public void destroyMethod(){ |
| System.out.println("执行第五步,销毁的方法"); |
| } |
| } |
| package com.guodaxia.bean.lifttime; |
| |
| |
| import org.springframework.context.support.ClassPathXmlApplicationContext; |
| |
| public class Main { |
| public static void main(String[] args) { |
| ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean.xml"); |
| TestTime time = context.getBean("mybean",TestTime.class); |
| System.out.println("执行第四步,创建bean对象"); |
| System.out.println(time); |
| } |
| } |
| <?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="mybean" class="com.guodaxia.bean.lifttime.TestTime" init-method="initMethod" destroy-method="destroyMethod"> |
| <property name="name" value="苹果"></property> |
| </bean> |
| </beans> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)