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 技术体系 分布式配置 服务注册/发 ...
随机推荐
- 备份MySQL数据库并上传到阿里云OSS存储
1. 环境配置 要将本地文件上传到阿里云oss中, 必须使用阿里云提供的工具 ossutil, 有32位,也有64位的, Linux和Windows都有.具体可以到阿里云官网下载 官网及文档: htt ...
- json与java bean对象转换
第一步:引入fastjson的依赖jar包 注:如果引入此版本的依赖,导致项目不能启动(报错:找不到启动类);那么可以换一个版本的fastjson即可. 给出文字版: <!-- fastjson ...
- luogu 1144
最短路计数 #include <bits/stdc++.h> using namespace std; , M = 2e6 + ; << ); #define gc getch ...
- luogu P2345 奶牛集会
二次联通门 : luogu P2345 奶牛集会 /* luogu P2345 奶牛集会 权值线段树 以坐标为下标, 坐标为值建立线段树 对奶牛按听力由小到大排序 对于要查的牛 每次第i次放入奶牛起作 ...
- testdisk修复磁盘文件
使用testdisk,分析之后,使用:P ,list文件,然后使用如下方法恢复文件 Use Right to change directory, h to hide Alternate Data St ...
- 怎么写一个带 bin 的 npm 包
只需要2步: 1. 在package.json 定义 一下 : { "name": "my-cli", ..., "bin": { &quo ...
- 使用dig进行DNS查询
dig全称Domain Information Groper,是一个DNS域名信息查询的工具,可以使用来查看域名解析的过程. dig是linux下自带的工具,如果要在windows下使用需要自行下载和 ...
- Python的is和==
is是对比地址:==是对比值
- 使用Python调用Zabbix API
Zabbix API官方文档: https://www.zabbix.com/documentation/4.0/zh/manual/api 1.向 api_jsonrpc.php 发送HTTP_PO ...
- Java核心复习——CompletableFuture
介绍 JDK1.8引入CompletableFuture类. 使用方法 public class CompletableFutureTest { private static ExecutorServ ...