之前介绍了在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的更多相关文章

  1. 【Spring】1、Spring 中的监听器 Listener

    一.接口 1.EventListener 2.HttpSessionAttributeListener   继承EventListener接口 HttpSessionAttributeListener ...

  2. Spring Boot 整合监听器

    Listener是servlet规范中定义的一种特殊类,用于监听servletContext.HttpSession和servletRequest等域对象的创建和销毁事件,监听域对象的属性发生修改的事 ...

  3. spring boot 之监听器ApplicationListener

    监听器ApplicationListener 就是spring的监听器,能够用来监听事件,典型的观察者模式.ApplicationListener和ContextRefreshedEvent一般都是成 ...

  4. Spring boot 注册Filter , Listener, Servlet

    1: ServletRegistrationBean   Servlet @Bean public ServletRegistrationBean myServlet(){ ServletRegist ...

  5. 从零开始的Spring Boot(2、在Spring Boot中整合Servlet、Filter、Listener的方式)

    在Spring Boot中整合Servlet.Filter.Listener的方式 写在前面 从零开始的Spring Boot(1.搭建一个Spring Boot项目Hello World):http ...

  6. Spring Boot SpringApplication启动类(二)

    目录 前言 1.起源 2.SpringApplication 运行阶段 2.1 SpringApplicationRunListeners 结构 2.1.1 SpringApplicationRunL ...

  7. Spring Boot 外部化配置(一)- Environment、ConfigFileApplicationListener

    目录 前言 1.起源 2.外部化配置的资源类型 3.外部化配置的核心 3.1 Environment 3.1.1.ConfigFileApplicationListener 3.1.2.关联 Spri ...

  8. spring boot到底帮我们做了那些事?

    一.前言     上一篇介绍了注解,也是为这一篇做铺垫,传统的都是通过配置文件来启动spring,那spring boot到底是做了什么能让我们快速开发昵? 二.启动原理     看下程序启动的入口, ...

  9. Spring Boot系列(四) Spring Cloud 之 Config Client

    Config 是通过 PropertySource 提供. 这节的内容主要是探讨配置, 特别是 PropertySource 的加载机制. Spring Cloud 技术体系 分布式配置 服务注册/发 ...

随机推荐

  1. Soda Theme sublime 自定义编辑器主题

    1.Soda ThemeSublime Text 3中较为常用的一款自定义编辑器主题,用过的人都说好.Soda Theme包含代码着色.标签.图标,拥有light和dark两种颜色主题便于用户在不同时 ...

  2. php常量和变量之变量引用

    变量引用 变量引用很多老师喜欢来用C语言的指针来去讲解.我们作为有这么多年开发和教学经验的人来说——大多数学习PHP的人来说根本不了解C语言. 使用C语言一指针来讲解变量引用,我们觉得画蛇填足.并且, ...

  3. JAVA的循环结构进阶

    1.什么是二重循环:                        一个循环体内又包含另一个完整的循环结构                     语法:                       ...

  4. msf爆破

    SSH服务口令猜解: msf > use auxiliary/scanner/ssh/ssh_loginmsf auxiliary(ssh_login) > show optionsmsf ...

  5. 三十九.NoSQL概述 部署Redis服务 、 部署LNMP+Redis

    1. 搭建Redis服务器 在主机 192.168.4.50 上安装并启用 redis 服务 设置变量test,值为123 查看变量test的值   1.1 搭建redis服务器 1.1.1 安装re ...

  6. Python多线程笔记(一)

    Python中使用threading模块来实现多线程 threading提供一些常用的方法 threading.currentThread() 返回当前的线程变量 threading.enumerat ...

  7. Bzoj 2820: YY的GCD(莫比乌斯反演+除法分块)

    2820: YY的GCD Time Limit: 10 Sec Memory Limit: 512 MB Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x& ...

  8. 01.Flink笔记-编译、部署

    Flink开发环境部署配置 Flink是一个以Java及Scala作为开发语言的开源大数据项目,代码开源在github上,并使用maven来编译和构建项目.所需工具:Java.maven.Git. 本 ...

  9. Lua 常用函数 一

    lua_getallocf lua_Alloc lua_getallocf (lua_State *L, void **ud); 返回给定状态机的内存分配器函数.如果 ud 不是 NULL ,Lua ...

  10. redis简单消息队列

    <?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); $redis->flushall(); $redis-& ...