SpringBoot整合Lintener
1.通过扫描完成Lintener组件的注册
1.1编写Listener
/**
* springboot整合Lintener 方式一
* 在web.xml中如何配置Listener
* <listener>
* <listener-class>com.demo.istener.FirstListener</listener-class>//实例化listener全名
* </listener>
*
* servlet上下文的监听器
*/
@WebListener
public class FirstListener implements ServletContextListener {
/**
* 当servlet容器终止web
*
* @param sce
*/
@Override
public void contextDestroyed(ServletContextEvent sce) { } /**
* 当servletr容器启动web
* @param sce
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("Listener....init...");
}
}
1.2编写启动类
/**
* springboot整合Lintener 方式一
*/
@SpringBootApplication
@ServletComponentScan
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
1.3启动main方法

2.通过方法完成Lintener组件的注册
2.1 编写Listener
/**
* springboot整合Lintener 方式二
*/
public class SecondListener implements ServletContextListener { /**
* servletr容器启动web
* @param sce
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("SecondListener....init...");
} /**
* servlet容器终止web
* @param sce
*/
@Override
public void contextDestroyed(ServletContextEvent sce) { }
}
2.2编写启动类
/**
* springboot整合Lintener 方式二
*/
@SpringBootApplication
public class App2 {
public static void main(String[] args) {
SpringApplication.run(App2.class,args);
} /**
* 注册Listener
* @return
*/
@Bean
public ServletListenerRegistrationBean<SecondListener> getServletListenerRegistrationBean(){
ServletListenerRegistrationBean<SecondListener> bean=new ServletListenerRegistrationBean<>(new SecondListener());
return bean;
}
}
2.3启动,结果

小结 整合Listener两种方式:1.@WebListener @SpringBootApplication @ServletContenerScan 2.@SpringBootApplication @Bean ServletListenerRegistrationBean<SecondListener>
SpringBoot整合Lintener的更多相关文章
- spring-boot整合mybatis(1)
sprig-boot是一个微服务架构,加快了spring工程快速开发,以及简便了配置.接下来开始spring-boot与mybatis的整合. 1.创建一个maven工程命名为spring-boot- ...
- SpringBoot整合Mybatis之项目结构、数据源
已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...
- springboot整合mq接收消息队列
继上篇springboot整合mq发送消息队列 本篇主要在上篇基础上进行activiemq消息队列的接收springboot整合mq发送消息队列 第一步:新建marven项目,配置pom文件 < ...
- springboot整合mybaits注解开发
springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...
- SpringBoot整合Redis、ApachSolr和SpringSession
SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...
- SpringBoot整合ElasticSearch实现多版本的兼容
前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...
- SpringBoot整合Kafka和Storm
前言 本篇文章主要介绍的是SpringBoot整合kafka和storm以及在这过程遇到的一些问题和解决方案. kafka和storm的相关知识 如果你对kafka和storm熟悉的话,这一段可以直接 ...
- SpringBoot整合SpringCloud搭建分布式应用
什么是SpringCloud? SpringCloud是一个分布式的整体解决方案.SpringCloud为开发者提供了在分布式系统中快速构建的工具,使用SpringCloud可以快速的启动服务或构建应 ...
- SpringBoot整合RabbitMQ-整合演示
本系列是学习SpringBoot整合RabbitMQ的练手,包含服务安装,RabbitMQ整合SpringBoot2.x,消息可靠性投递实现等三篇博客. 学习路径:https://www.imooc. ...
随机推荐
- 【React -- 9/100】 抽离顶部导航栏 - [组件复用]
今天写的页面中需要重复使用到顶部导航栏,所以把顶部导航栏抽离出来 考虑复用组件的健壮性,使用PropTypes校验,可以自定义一个click事件 JSX import React from " ...
- JS 的 Browser对象
Window对象 closed innerHeight 窗口文档显示区的高度,包括滚动条 outerHeight 窗口总高度,包括工具条和滚动条 open() close() alert( ...
- java程序员究竟应该掌握点什么
JAVA程序设计(基础部分) JAVA程序设计(专题)
- 继续死磕python
一.数据运算 算术运算 比较运算 赋值运算 逻辑运算 成员运算 身份运算 位运算 其中左右移运算是逻辑左右移即缺失位补0,而算数右移缺失补符号位(注意逻辑运算都是补码运算即都取补码再运算,然后结果也是 ...
- NLP 中任务及相关概念
命名实体识别 命名实体识别(Named Entity Recognition,简称NER),又称作"专名识别",是指识别文本中具有特定意义的实体,主要包括人名.地名.机构名.专有名 ...
- Codeforces Round #427 (Div. 2) - C
题目链接:http://codeforces.com/contest/835/problem/C 题意:在二维坐标里,有n个星星,m个询问,星星的最大亮度c.然后输入n个星星的坐标和初始亮度,对于每个 ...
- GUI学习之三十二—QLCDNumber学习总结
下面我们来总结一下QLCDNumber的用法 一.描述 QLCDNumber主要用来展示LCD样式的数字,他可以显示几乎任何大小的数字,可以显示十进制,十六进制,八进制或二进制数,也可以展示一些简单的 ...
- java 分页对象以及数据库分页查询
import java.util.List; public class Pager<T> { private Integer pageSize; private Integer total ...
- FAT12
FAT12 is one of FAT file system families,mostly used on 1.44MB floppy disk. FAT 's full name is File ...
- 前端每日实战:12# 视频演示如何用纯 CSS 创作一种文字断开的交互特效
效果预览 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/pen/LmjNgL 可交互视频教程 此视频是可以交 ...