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 技术体系 分布式配置 服务注册/发 ...
随机推荐
- Oracle LOB 大对象处理
LOB类型列主要是用来存储大量数据的数据库字段,最大可以存储4G字节的非结构化数据. 一.LOB数据类型分类 1.按存储数据的类型分: ①字符类型: CLOB:存储大量 单字节 字符数据. N ...
- SpringBoot项目启动报错:java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | ...
- BLOB和TEXT
区别: BLOB存储的是二进制数据,没有排序规则或字符集. TEXT存储的是字符,有排序规则和字符集. 因为Memory引擎不支持BLOB和TEXT类型,最好的解决方案避免使用BLOB和TEXT类型. ...
- java中创建对象的方式
Java中有5种创建对象的方式,下面给出它们的例子还有它们的字节码 使用new关键字 } → 调用了构造函数 使用Class类的newInstance方法 } → 调用了构造函数 使用Construc ...
- java中byte的范围计算
概念:java中用补码表示二进制数,补码的最高位是符号位,最高位为“0”表示正数,最高位为“1”表示负数.正数补码为其本身:负数补码为其绝对值各位取反加1:例如:+21,其二进制表示形式是000101 ...
- python - django (auth 的使用)
# """ 1. 创建用户: python manage.py createsuperuser 2. from django.contrib import auth au ...
- pstmt.getGeneratedKeys()更换jar包后报错
改成: pstmt=conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); rs=pstmt.getGeneratedKeys(); 即 ...
- 爬虫(四):BeautifulSoup库的使用
一:beautifulsoup简介 beautifulsoup是一个非常强大的工具,爬虫利器. beautifulSoup “美味的汤,绿色的浓汤” 一个灵活又方便的网页解析库,处理高效,支持多种解析 ...
- ubuntu中防火墙iptables配置
特别说明:此文章完全转载于https://www.cnblogs.com/EasonJim/p/6851007.html 1.查看系统是否安装防火墙 root@localhost:/usr# whic ...
- hadoop笔记-hdfs文件读写
概念 文件系统 磁盘进行读写的最小单位:数据块,文件系统构建于磁盘之上,文件系统的块大小是磁盘块的整数倍. 文件系统块一般为几千字节,磁盘块一般512字节. hdfs的block.pocket.chu ...