spring中ApplicationListener的用法
1、实现ApplicationListener接口,并重写onApplicationEvent方法
@Component
public class RSAKeyInitListener implements ApplicationListener<ContextRefreshedEvent> { @Autowired
BaseAppConfigDao baseAppConfigDao; @Override
public void onApplicationEvent(ContextRefreshedEvent event) {
//具体操作
}
}
2、创建spring的应用上下文(ApplicationContext.xml),并配置注解扫描
<context:component-scan base-package="com.xxx.xxx.facex.listener" />
3、配置web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 也可以与context-param标签一起使用 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
spring中ApplicationListener的用法的更多相关文章
- 框架源码系列十:Spring AOP(AOP的核心概念回顾、Spring中AOP的用法、Spring AOP 源码学习)
一.AOP的核心概念回顾 https://docs.spring.io/spring/docs/5.1.3.RELEASE/spring-framework-reference/core.html#a ...
- Spring中ApplicationListener的使用
背景 ApplicationListener是Spring事件机制的一部分,与抽象类ApplicationEvent类配合来完成ApplicationContext的事件机制. 如果容器中存在Appl ...
- Spring中@Cacheable的用法
在Spring中通过获取MemCachedClient来实现与memcached服务器进行数据读取的方式.不过,在实际开发中,我们往往是通过Spring的@Cacheable来实现数据的缓存的,所以, ...
- Spring中HibernateCallback的用法(转)
Hibernate的复杂用法HibernateCallback HibernateTemplate还提供一种更加灵活的方式来操作数据库,通过这种方式可以完全使用Hibernate的操作方式.Hiber ...
- Spring中jdbcTemplate的用法实例
一.首先配置JdbcTemplate: 要使用Jdbctemplate 对象来完成jdbc 操作.通常情况下,有三种种方式得到JdbcTemplate 对象. 第一种方式:我们可以在自己定 ...
- Spring 中classPath:用法
参考文章地址: http://hi.baidu.com/huahua035/item/ac8a27a994b55bad29ce9d39 http://blog.csdn.net/lushuaiyin/ ...
- spring 中StoredProcedure的用法--转载
StoredProcedure是一个抽象类,必须写一个子类来继承它,这个类是用来简化JDBCTemplate执行存储过程操作的. 首先我们写一个实现类: package com.huaye.frame ...
- Spring中ApplicationContextAware的用法
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt379 一.这个接口有什么用? 当一个类实现了这个接口(Application ...
- Spring中RedirectAttributes的用法
RedirectAttributes 是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的的工具类.他有两种带参的方式: 第一种: redirectAttribut ...
随机推荐
- 论文笔记:Auto-DeepLab: Hierarchical Neural Architecture Search for Semantic Image Segmentation
Auto-DeepLab: Hierarchical Neural Architecture Search for Semantic Image Segmentation2019-03-18 14:4 ...
- chromdriver与geckodriver和浏览器版本问题
chromdriver74与chrom74对应 geckodriver024与Firefox66对应 亲测有效
- web 后台返回json格式数据的方式(status 406)
1.在类上使用注解 @RestController public class HttpComentInterface { } 2.在方法是使用注解 @ResponseBody @RequestMap ...
- JAVA-重载(overload)和重写(overrite)
1.重载发生在同一个类中.有多个方法名相同,但是参数列表不同(包括参数个数和参数类型),和返回值无关,权限修饰符也无关. 2.重写(即覆盖)发生在子类和父类中.子类和父类的方法名.参数列表相同:子类的 ...
- php正则匹配
在PHP中,有两套正则表达式函数库,两者功能相似,只是执行效率上有所不同, 一套是有"preg_"为前缀命名的函数,一套有"ereg_"命名的函数的函数, 一个 ...
- Activity与Fragment数据传递之Fragment从Activity获取数据
整理Fragment与Activity之间的数据交换,大体上包括三种: 1.Fragment从Activity获取数据 2.Activity从Fragment获取数据 3.Fragment之间获取数据 ...
- pyhton课堂随笔-基本画图
%matplotlib inline import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np impor ...
- FreeMarker与Thymeleaf
FreeMarker 是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯 Java 编写,FreeMarker 被设计用来生成 HTML Web 页面,特别是基于 MVC 模式的应用程序,虽然 ...
- 可迭代对象 TO 迭代器
可迭代对象并不是迭代器,只是支持迭代.可被for循环遍历的对象,比如list,dict ,tuple ,string都是可迭代对象 那既然支持迭代,那要如何用迭代替换for循环呢? 内置函数 iter ...
- JS数组遍历
1. forEach() 循环数组,不会改变元素,不会返回新数组 arr.foreach((value,index)=>{}) 2. map() 遍历数组,对每个元素进行处理,之后返回元素:会返 ...