4.1.新建一个Demo2的实体类;

package com.eduask.entity;

//新建一个Demo2的实体类;

public class Demo2 {

public void init(){

System.out.println("这是init方法");

}

public void destory(){

System.out.println("调用cx.close方法之后");

System.out.println("这是destory方法");

}

}

4.2新建一个TestDemo2的测试类

package com.eduask.entity;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDemo2 {

public static void main(String[] args) {

ClassPathXmlApplicationContext cx=new ClassPathXmlApplicationContext("demo2.xml");

Demo2 demo2=(Demo2) cx.getBean("Demo2");

//只有当执行cx.close方法时,Demo2中的destory方法才会被执行;

cx.close();

}

}

4.3 新建一个demo2.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="Demo2" class="com.eduask.entity.Demo2" init-method="init" destroy-method="destory">

</bean>

</beans>

init和destory方法相关推荐

  1. 【spring 的 init and destory 方法】

    [spring 的 init and  destory 方法] <?xml version="1.0" encoding="UTF-8"?> < ...

  2. servlet中init,service,destory方法描述

    init()方法是servlet生命的起点.一旦加载了某个servlet,服务器将立即调用它的init()方法. service()方法处理客户机发出的所有请求,由web容器调用. destory() ...

  3. Spring XML 和 注解形式指定init 、destory方法

    XML形式 <bean class="you.class" init-method="initMethod", destroy-method=" ...

  4. 过滤器Filter方法详解(init,doFileter,destory)

    过滤器Filter 过滤器如何实现拦截? Filter接口 Filter生命周期 1.Filter接口中三个重要的方法 2.Filter的生命周期 Filter对象 - FilterConfig 过滤 ...

  5. Servlet本身的init,service,destory生命周期方法

    init,service,destory生命周期 由容器管理Servlet对象的生命周期(创建对象,初始化,销毁) 处理请求时,调用Servlet对象的方法 tomcat:称为web服务器,也称为Se ...

  6. Spring bean的生命周期init和destory

    Bean生命周期:定义 --- 初始化 --- 使用 --- 销毁 一.初始化: 方法1.实现org.springframework.beans.foctory.InitializingBean接口, ...

  7. java servlet init方法_JSP开发Servlet重写init()方法实例详解

    jsp开发servlet重写init()方法实例详解 写一个servlet时,有时需要我们重写该servlet的初始化方法,然后,究竟是重写init(servletconfig config),还是重 ...

  8. servlet中destory方法的误解

    最近学习servlet的过程中发现了一个很怪的问题, 百度上面搜索这个问题也几乎都是错误的理解.那就是有关servlet在什么时候摧毁,回答很多是服务器关闭或者执行destory方法.服务器关闭ser ...

  9. Laravel 资源管理器 destory方法

    生成一个控制器 php artisan make:controller -r Admin/UsersController 在命名空间 Admin 下 路由如下 Route::namespace('Ad ...

最新文章

  1. codevs1137 计算系数
  2. C#中的Dictionary简介
  3. 想转行?零基础该如何学Python?这些一定要明白
  4. WebSphere Application Server 5.0在Linux平台上中文界面乱码问题的解决
  5. Manacher算法图解
  6. Linux中软件安装使用的命令是,Linux软件安装命令
  7. Python数据结构与算法(三)--数据结构的概念
  8. 动态编译 java ASM入门
  9. HTML超链接使用代码
  10. ST-Link驱动的下载、安装、配置,以及ST-Link固件的升级
  11. Detours内联HOOK
  12. 服务器server.c、搜索serach.c
  13. 2021年中国机动车保有量及机动车污染物排放情况分析[图]
  14. Pollard rho整数分解法
  15. 庐山石刻分布及实习感想
  16. ListView控件的理解——自洽理论
  17. 人心本无染,心静自然清 ——赞“落梅”
  18. 27岁年入千万的李佳琦:以为钱很好赚,是年轻人的最大错觉
  19. JAVA实现车牌随机产生器
  20. 什么是网站权重?如何提高网站权重?

热门文章

  1. u盘有图标计算机显示没有,电脑没插u盘却显示u盘图标是怎么回事?
  2. 对方接住了你人的php,接住你了表情包 - 接住你了微信表情包 - 接住你了QQ表情包 - 发表情 fabiaoqing.com...
  3. MySQL 使用 Workbench 建表时 PK NN UQ BIN UN ZF AI G 的含义
  4. kaggle员工离职预测——SVC
  5. 利弗莫尔的操作系统到底是怎样的?
  6. 怎么卸载光速头条_教你怎么卸载光速浏览器
  7. ABAP select options 和 parameters在同一行
  8. ffmpeg libx264 h264_nvenc 编码参数解析
  9. 基于微信小程序的校园二手图书设计与开发
  10. python 词库 匹配_python从一段文本中找出存在于词库的词语