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. ...
随机推荐
- JS 的 Browser对象
Window对象 closed innerHeight 窗口文档显示区的高度,包括滚动条 outerHeight 窗口总高度,包括工具条和滚动条 open() close() alert( ...
- Apache 配置外网站点
基于域名,一般是对外网站 www.etiantian.org/var/www/html/www blog.etiantian.org /var/www/html/blog bbs.tiantian.o ...
- First one Day(哈哈哈哈)
今天是我来到园子的第一天,后序会分享一些自己所学的知识(当然我知道没人看,但是我自己看就好).哈哈哈哈哈 请大家多多关照!
- LVS集群的ipvsadm命令用法
准备一台Linux服务器,安装ipvsadm软件包,练习使用ipvsadm命令,实现如下功能: - 使用命令添加基于TCP一些的集群服务 - 在集群中添加若干台后端真实服务器 - 实现同一客户端访问, ...
- STM32内核简介
STM32F407 的内核是cortex-M4 采用的是ARM架构,具体是ARM-V7架构. 而ARM-V7架构分为三个系列: 1>.A系列:面向尖端的基于虚拟内存的操作系统和用户应用: 2 ...
- 神经风格转换 (Neural-Style-Transfer-Papers)
原文:https://github.com/ycjing/Neural-Style-Transfer-Papers Neural-Style-Transfer-Papers Selected pape ...
- Behavior行为
创建公用的js 模块 封装起来 let behavior = Behavior({//定义属性 properties: { type: String, img: String, content: St ...
- MySQL把多条数据给汇总成一条数据
用到的是这个函数: group_concat() select group_buying_id, group_concat(app_user_ids) from org_user_group grou ...
- height设置百分比的条件
很多时候我们在给height设置百分比的时候不起作用, 这时候就要来谈谈什么情况下才起作用了 1)所有父级元素必须有高度: 2)必须是块级元素,行内元素不起作用: 3)ie9 以下 使用 positi ...
- (26)Python获取某个文件存放的相对路径(更改任意目录下保持不变)
import os import platform def getSeparator(): ''' 获取不同平台下的斜杠符号 :return: Created by Wu Yongcong 2017- ...