SpringMVC事件监听ApplicationListener实例解析
这篇文章主要介绍了SpringMVC事件监听ApplicationListener实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
1. 实现 ApplicationListener<T> 接口(T为监听类型,稍后会列出具体可监听事件)
2. 将该自定义监听类,注册为Spring容器组件。(即将该类注入Spring容器)
实例:
该类监听ServletRequestHandledEvent事件,该事件为请求结束回调事件,即一个请求完成结束后会执行onApplicationEvent内自定义业务逻辑。
package com.xxxxxx.xxxxxx.listener; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; import org.springframework.web.context.support.ServletRequestHandledEvent; @Component public class RequestedListener implements ApplicationListener<ServletRequestHandledEvent> { @Override public void onApplicationEvent(ServletRequestHandledEvent event) { System.out.println("requested event listener: " + event.getRequestUrl()); } }
可使用监听事件类型(所有可使用监听事件类型均继承自org.springframework.context.ApplicationEvent类):
- 具体监听事件可根据类型 google baidu 搜索。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
相关推荐
-
Spring Boot 编写Servlet、Filter、Listener、Interceptor的方法
前言 在编写过滤器.监听器.拦截器之前我们需要在spring-boot启动的类上加上注解@ServletComponentScan: @SpringBootApplication @ServletComponentScan public class MySpringbootApplication { public static void main(String[] args) { SpringApplication.run(MySpringbootApplication.class, args)
-
SpringMVC拦截器实现监听session是否过期详解
本文主要向大家介绍了SpringMVC拦截器实现:当用户访问网站资源时,监听session是否过期的代码,具体如下: 一.拦截器配置 <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <mvc:exclude-mapping path="/user/login"/> <!-- 不拦截登录请求 --> <mvc:exclude-
-
springBoot的事件机制GenericApplicationListener用法解析
什么是ApplicationContext? 它是Spring的核心,Context我们通常解释为上下文环境,但是理解成容器会更好些. ApplicationContext则是应用的容器. Spring把Bean(object)放在容器中,需要用就通过get方法取出来. ApplicationEvent 是个抽象类,里面只有一个构造函数和一个长整型的timestamp. springboot的event的类型: ApplicationStartingEvent ApplicationEnviro
-
Spring MVC之WebApplicationContext_动力节点Java学院整理
如果你使用了listener监听器来加载配置,一般在Struts+Spring+Hibernate的项目中都是使用listener监听器的.如下 Java代码 <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> Spring会创建一个WebApplicationContext上下文,称为父上下
-
Spring boot通过HttpSessionListener监听器统计在线人数的实现代码
首先说下,这个统计在线人数有个缺陷,一个人在线可以同时拥有多个session,导致统计有一定的不准确行. 接下来,开始代码的编写, 第一步:实现HttpSessionListener中的方法,加上注解@WebListener @WebListener public class SessionListener implements HttpSessionListener{ public void sessionCreated(HttpSessionEvent arg0) { // TODO Aut
-
Spring Boot的listener(监听器)简单使用实例详解
监听器(Listener)的注册方法和 Servlet 一样,有两种方式:代码注册或者注解注册 1.代码注册方式 通过代码方式注入过滤器 @Bean public ServletListenerRegistrationBean servletListenerRegistrationBean(){ ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean
-
Spring ApplicationListener监听器用法详解
这篇文章主要介绍了Spring ApplicationListener监听器用法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 监听器在使用过程中可以监听到某一事件的发生,进而对事件做出相应的处理. 首先自定义一个监听器myListener实现ApplicationListener接口 @Repository public class myListener implements ApplicationListener<Application
-
基于springMvc+hibernate的web application的构建
闲来没事,想整理下一些知识. 这篇文章是关于spring的web程序的搭建,有什么不对的地方希望大家批评指正. 首先我们要了解什么是spring,这里可能很多大家也都明白,无非是一个管理对象的一个容器,主要体现在IOC注入和AOP切面编程. 关于上面的两点在后面一点会给大家更具体的说明一下是什么. 简单的来说,以前大家编程实例化都是自己在控制,这样真的好吗? 下面是不用spring的写法,我们先假定有一个类是下面这样的: public class Worker { public void say
-
SpringMVC事件监听ApplicationListener实例解析
这篇文章主要介绍了SpringMVC事件监听ApplicationListener实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1. 实现 ApplicationListener<T> 接口(T为监听类型,稍后会列出具体可监听事件) 2. 将该自定义监听类,注册为Spring容器组件.(即将该类注入Spring容器) 实例: 该类监听ServletRequestHandledEvent事件,该事件为请求结束回调事件,即一个请求完成结
-
微信小程序实现拖拽 image 触摸事件监听的实例
微信小程序实现拖拽 image 触摸事件监听的实例 需要做个浮在scroll-view之上的button.尝试了一下. 实现效果图: Android中也会有类似移动控件的操作.思路差不多.获取到位移的X Y 的变量,给控件设置坐标. 1.index.wxml <image class="image-style" src="../../images/gundong.png" bindtap="ballClickEvent" style=&qu
-
JavaScript使用addEventListener添加事件监听用法实例
本文实例讲述了JavaScript使用addEventListener添加事件监听用法.分享给大家供大家参考.具体实现方法如下: <!DOCTYPE html> <html lang="en"> <head> <title>This text is the title of the document</title> <script> function showalert(){ alert('you clicked
-
Android开发之button事件监听简单实例
本文实例讲述了Android开发之button事件监听用法.分享给大家供大家参考.具体如下: 事件监听的listener,有以下几种方式: 1.声明一个普通的class,实现OnClickListener接口,然后在button的setOnClickListener中new该类的一个对象. 2.使用匿名内部类,直接 btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { S
-
Spring boot事件监听实现过程解析
事件监听其实我们并不陌生,简单来讲,当程序达到了某个特定的条件,程序就会自动执行一段指令.在spring 中也一样,我们可以使用spring中的事件监听来实现某些特定的需求. 发布事件 既然要监听事件,首先要发布我们的事件嘛.在spring中发布事件我们可以通过继承ApplicationEvent 来发布我们的事件类. @Data public class SendEvent extends ApplicationEvent { public SendEvent(Object source) {
-
springboot+redis过期事件监听实现过程解析
1 修改 redis.conf配置文件: K Keyspace events, published with keyspace@ prefix事件 E Keyevent events, published with keyevent@ prefix g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, - $ String commands l List commands s Set commands h Hash co
-
JavaScript 事件监听实例代码[兼容IE,firefox] 含注释
JavaScript事件监听完整实例(含注释) var oEventUtil = new Object(); oEventUtil.AddEventHandler = function(oTarget,sEventType,fnHandler) { //IE和FF的兼容性处理 //如果是FF if(oTarget.addEventListener){ oTarget.addEventListener(sEventType,fnHandler,false); } //如果是IE else if(o
-
jQuery绑定事件监听bind和移除事件监听unbind用法实例详解
本文实例讲述了jQuery绑定事件监听bind和移除事件监听unbind用法.分享给大家供大家参考,具体如下: 这里分别采用后bind(eventType,[data],Listener)//data为可选参数,one()该方法绑定的事件触发一次后自动删除,unbind(eventType,Listener), 实例: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w
-
JavaScript为事件句柄绑定监听函数实例详解
本文实例讲述了JavaScript为事件句柄绑定监听函数的方法.分享给大家供大家参考,具体如下: 在JavaScript中为Dom元素绑定事件监听函数是一件非常常见的事情,但这里也有许多的Bug.各种浏览器对于事件绑定都提供了很多方法,但可靠的只有3中: 1.传统的绑定方法: elem.onclick = function( event ){ alert(event.type + 'this.innerHTML'); }; a.传统的绑定方法,非常简单稳定,函数体内的this指向的也是指向正在处
-
微信小程序 实现拖拽事件监听实例详解
微信小程序 拖拽监听功能: 在软件开发或者 APP应用开发的时候,经常会遇到拖拽监听,最近自己学习微信小程序的知识,就想实现这样的拖拽效果,这里就记录下. 需要做个浮在scroll-view之上的button.尝试了一下. 上GIF: Android中也会有类似移动控件的操作.思路差不多.获取到位移的X Y 的变量,给控件设置坐标. 1.index.wxml ../images/gundong.png" bindtap="ballClickEvent" style="
随机推荐
- C++常用字符串分割方法实例汇总
- Http与https对比详细介绍
- JavaScript数组复制详解
- Bootstrap列表组学习使用
- iOS中常见正则表达式验证方法
- iOS的CoreAnimation开发框架中的Layer层动画制作解析
- 实例解析iOS应用多线程开发中NSthread类的用法
- javaweb上传下载实例完整版解析(下)
- C#后台调用前台javascript的五种方法小结
- JavaScript event对象整理及详细介绍
- smarty模板引擎之内建函数用法
- JAVA velocity模板引擎使用实例
- C++初始化函数列表详细解析
- mySQL count多个表的数据实例详解
- C#实现实体类和XML相互转换
- C++模板类的用法实例
- jquery dialog open后,服务器端控件失效的快速解决方法
- 关于jQuery中.attr()和.prop()的问题探讨
- Java的JDBC中Statement与CallableStatement对象实例
- ASP.NET实现用户注册和验证功能(第4节)