Spring Boot使用监听器Listener
之前介绍了在Spring Boot中使用过滤器:https://www.cnblogs.com/zifeiy/p/9911056.html
接下来介绍使用监听器Listener。
下面是一个例子:
package com.zifeiy.test.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class TestUserListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
// TODO Auto-generated method stub
ServletContextListener.super.contextInitialized(sce);
System.out.println("ServletContext上下文初始化!");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
ServletContextListener.super.contextDestroyed(sce);
System.out.println("ServletContext上下文销毁!");
}
}
在程序启动的时候,可以看到初始化函数调用的结果:
ServletContext上下文初始化!
Spring Boot使用监听器Listener的更多相关文章
- 【Spring】1、Spring 中的监听器 Listener
一.接口 1.EventListener 2.HttpSessionAttributeListener 继承EventListener接口 HttpSessionAttributeListener ...
- Spring Boot 整合监听器
Listener是servlet规范中定义的一种特殊类,用于监听servletContext.HttpSession和servletRequest等域对象的创建和销毁事件,监听域对象的属性发生修改的事 ...
- spring boot 之监听器ApplicationListener
监听器ApplicationListener 就是spring的监听器,能够用来监听事件,典型的观察者模式.ApplicationListener和ContextRefreshedEvent一般都是成 ...
- Spring boot 注册Filter , Listener, Servlet
1: ServletRegistrationBean Servlet @Bean public ServletRegistrationBean myServlet(){ ServletRegist ...
- 从零开始的Spring Boot(2、在Spring Boot中整合Servlet、Filter、Listener的方式)
在Spring Boot中整合Servlet.Filter.Listener的方式 写在前面 从零开始的Spring Boot(1.搭建一个Spring Boot项目Hello World):http ...
- Spring Boot SpringApplication启动类(二)
目录 前言 1.起源 2.SpringApplication 运行阶段 2.1 SpringApplicationRunListeners 结构 2.1.1 SpringApplicationRunL ...
- Spring Boot 外部化配置(一)- Environment、ConfigFileApplicationListener
目录 前言 1.起源 2.外部化配置的资源类型 3.外部化配置的核心 3.1 Environment 3.1.1.ConfigFileApplicationListener 3.1.2.关联 Spri ...
- spring boot到底帮我们做了那些事?
一.前言 上一篇介绍了注解,也是为这一篇做铺垫,传统的都是通过配置文件来启动spring,那spring boot到底是做了什么能让我们快速开发昵? 二.启动原理 看下程序启动的入口, ...
- Spring Boot系列(四) Spring Cloud 之 Config Client
Config 是通过 PropertySource 提供. 这节的内容主要是探讨配置, 特别是 PropertySource 的加载机制. Spring Cloud 技术体系 分布式配置 服务注册/发 ...
随机推荐
- vue 对象更改检测注意事项
- Selenium常用API的使用java语言之3-selenium3 浏览器驱动
1.下载浏览器驱动 当selenium升级到3.0之后,对不同的浏览器驱动进行了规范.如果想使用selenium驱动不同的浏览器,必须单独下载并设置不同的浏览器驱动. 各浏览器下载地址: Firefo ...
- Linux 查看系统配置参数
原文链接:http://www.cnblogs.com/aric2016/p/10971690.html 查看 cpu信息: cat /proc/cpuinfo 查看内存信息: grep MemTot ...
- SpringMVC使用ResponseEntity实现文件下载,及图片base64的字节数组上传于下载
本文主要通过ResponseEntity<byte[]>实现文件下 该类实现响应头.文件数据(以字节存储).状态封装在一起交给浏览器处理以实现浏览器的文件下载. ResponseEntit ...
- 007_Python3 字符串
字符串是 Python 中最常用的数据类型.我们可以使用引号( ' 或 " )来创建字符串. 创建字符串很简单,只要为变量分配一个值即可. 例如: var1 = 'Hello World!' ...
- vue 的 watch 如何在初始化时执行
之前的做法一直是在 created 钩子之后手动调用一次 created() { this.fetchText(); }, watch: { text: 'fetchText', } 后来在翻阅文档的 ...
- 【luogu1251】餐巾计划问题--网络流建模,费用流
题目描述 一个餐厅在相继的 N 天里,每天需用的餐巾数不尽相同.假设第 iii 天需要 ri块餐巾( i=1,2,...,N).餐厅可以购买新的餐巾,每块餐巾的费用为 p 分;或者把旧餐巾送到快洗部 ...
- java1.8新特性之stream流式算法
在Java1.8之前还没有stream流式算法的时候,我们要是在一个放有多个User对象的list集合中,将每个User对象的主键ID取出,组合成一个新的集合,首先想到的肯定是遍历,如下: List& ...
- 【SPOJ】Longest Common Substring II
[SPOJ]Longest Common Substring II 多个字符串求最长公共子串 还是将一个子串建SAM,其他字符串全部跑一边,记录每个点的最大贡献 由于是所有串,要对每个点每个字符串跑完 ...
- c标签页面进行解析json
JAVA代码中的后台 List<Map<String,String>> rs = new ArrayList<Map<String,String>>() ...