【使用篇二】SpringBoot整合Listener(3)
两种方式:
- 通过注解扫描完成 Listener 组件的注册
- 通过方法完成 Listener 组件注册
一、通过注解扫描完成 Listener 组件的注册
1. 编写Listener类
/*** springBoot 整合 Listener 方式一:
**
** 传统方式 一:
** <listener>
** <listener-class>com.linhw.demo.listener.FirstListener</listener-class>
** </listener>
**/
@WebListener
public class FirstListener implements ServletContextListener{
@Override
public void contextInitialized(ServletContextEvent sce) {
//启动时,在控制台可以看到
System.out.println("Listener...init......");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
2. 编写启动类
@SpringBootApplication
@ServletComponentScan
public class App5 {
public static void main(String[] args) {
SpringApplication.run(App5.class, args);
}
}
二、通过方法完成 Listener 组件注册
1. 编写Listener类
//与第一种方式的区别,就是没有加@WebListener注解
public class SecondListener implements ServletContextListener{
@Override
public void contextInitialized(ServletContextEvent sce) {
//启动时,在控制台可以看到
System.out.println("Method Listener...init......");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
2. 编写启动类
@SpringBootApplication
public class App6 {
public static void main(String[] args) {
SpringApplication.run(App6.class, args);
}
//添加@Bean将名为"getListener"的bean加入到容器中
@Bean
public ServletListenerRegistrationBean<SecondListener> getListener(){
ServletListenerRegistrationBean<SecondListener> secondLisener = new ServletListenerRegistrationBean<SecondListener>(new SecondListener());
return secondLisener;
}
}
【使用篇二】SpringBoot整合Listener(3)的更多相关文章
- springBoot整合Listener
新建项目 这个是pom文件 <properties> <java.version>1.8</java.version> </properties> &l ...
- jackson学习之十(终篇):springboot整合(配置类)
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- Canal 实战 | 第一篇:SpringBoot 整合 Canal + RabbitMQ 实现监听 MySQL 数据库同步更新 Redis 缓存
一. Canal 简介 canal [kə'næl],译意为水道/管道/沟渠,主要用途是基于 MySQL 数据库增量日志解析,提供增量数据订阅和消费 早期阿里巴巴因为杭州和美国双机房部署,存在跨机房同 ...
- 02-03:springboot 整合listener
1.通过注解扫描完成Listener组件的注册 1.1 编写listener /** * Springboot 整合listener */ import javax.servlet.ServletCo ...
- 【SpringBoot】05.SpringBoot整合Listener的两种方式
SpringBoot整合Listener的两种方式: 1.通过注解扫描完成Listener组件的注册 创建一个类实现ServletContextListener (具体实现哪个Listener根据情况 ...
- SpringBoot非官方教程 | 第九篇: springboot整合Redis
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot9-redis/ 本文出自方志朋的博客 这篇文章主 ...
- springboot(二).springboot整合logback用于日志输出
springboot整合logback用于日志输出 我们项目的基本框架已经完成,http请求已经可以访问,现在给我们的框架添加日志记录的功能并能将每天的记录记录到文件中去 在这里,我们使用logbac ...
- SpringBoot从入门到精通二(SpringBoot整合myBatis的两种方式)
前言 通过上一章的学习,我们已经对SpringBoot有简单的入门,接下来我们深入学习一下SpringBoot,我们知道任何一个网站的数据大多数都是动态的,也就是说数据是从数据库提取出来的,而非静态数 ...
- 2018/3/4 Activiti教程之流程部署篇(与Springboot整合版)二
首先我们来看下Activiti为我们自动生成的这四张用户相关的表 先看下USER表 我已经插入了一些数据,很明显,就是保存用户的信息的 看下GROUP 用户对应的分组信息 MEMBERSHIP 用户和 ...
随机推荐
- python socket编程腾讯云下报错[Errno 99] Cannot assign requested address的解决方式
先写服务端server.py: import socket import time HOST = '172.17.xx.xx' #服务器的私网IP #HOST = 'localhost' PORT = ...
- 【新特性速递】树控件结构由单层 TR 改为 TR-TD-TABLE 层级嵌套
FineUIPro/Mvc/Core的下个版本(v6.1.0),我们对树控件进行了优化,由原来的单层 TR 改为 TR-TD-TABLE 层级嵌套,从而做到表里如一. 上个版本(v6.0.0),我们对 ...
- 使用git克隆github上的项目失败,报错error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
错误描述 今天在github上使用 git clone 某个项目代码的时, git clone https://github.com/XXXX/xxx-blog.git 下载速度很慢,然后下载一段时间 ...
- app版本升级的测试点
移动端版本更新升级是一个比较重要的功能点,主要分为强制更新和非强制更新. 1.强制更新需要测试的点有: 1)强制升级是否可以升级成功 从老版本的包升级到新版版的包是否可以升级成功. 2)升级后的数据是 ...
- redis延迟队列
异步消息队列 Redis 的 list(列表) 数据结构常用来作为异步消息队列使用,使用rpush/lpush操作入队列, 使用 lpop 和 rpop 来出队列. > rpush notify ...
- poj-3230 Travel
One traveler travels among cities. He has to pay for this while he can get some incomes. Now there a ...
- 如何判断服务器之间的服务是否可用?ping 还是 telnet?
1. 背景 机器A需要调用机器B的服务,为此要保证服务的可用性,我们有时候用ping,有时候用telent来验证机器A和B的连通性,但有时候会出现这种情况,A可以ping通B,但A调用B的服务会一直报 ...
- 用Python完成毫秒级抢单,助你秒杀淘宝大单
目录: 引言 环境 需求分析&前期准备 淘宝购物流程回顾 秒杀的实现 代码梳理 总结 0 引言 年中购物618大狂欢开始了,各大电商又开始了大力度的折扣促销,我们的小胖又给大家谋了一波福利,淘 ...
- Review: Basic Knowledge about WebForm
Asp.net shanzm
- Linux帮助——获取帮助
Linux帮助——获取帮助 摘要:本文主要学习了Linux众多命令中最基础的帮助命令. 介绍 作用 Linux的所有操作都可以通过命令行来完成,所以学习Linux最好从命令行开始.因为Linux的命令 ...