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的用法的更多相关文章

  1. 框架源码系列十:Spring AOP(AOP的核心概念回顾、Spring中AOP的用法、Spring AOP 源码学习)

    一.AOP的核心概念回顾 https://docs.spring.io/spring/docs/5.1.3.RELEASE/spring-framework-reference/core.html#a ...

  2. Spring中ApplicationListener的使用

    背景 ApplicationListener是Spring事件机制的一部分,与抽象类ApplicationEvent类配合来完成ApplicationContext的事件机制. 如果容器中存在Appl ...

  3. Spring中@Cacheable的用法

    在Spring中通过获取MemCachedClient来实现与memcached服务器进行数据读取的方式.不过,在实际开发中,我们往往是通过Spring的@Cacheable来实现数据的缓存的,所以, ...

  4. Spring中HibernateCallback的用法(转)

    Hibernate的复杂用法HibernateCallback HibernateTemplate还提供一种更加灵活的方式来操作数据库,通过这种方式可以完全使用Hibernate的操作方式.Hiber ...

  5. Spring中jdbcTemplate的用法实例

    一.首先配置JdbcTemplate: 要使用Jdbctemplate 对象来完成jdbc 操作.通常情况下,有三种种方式得到JdbcTemplate 对象.       第一种方式:我们可以在自己定 ...

  6. Spring 中classPath:用法

    参考文章地址: http://hi.baidu.com/huahua035/item/ac8a27a994b55bad29ce9d39 http://blog.csdn.net/lushuaiyin/ ...

  7. spring 中StoredProcedure的用法--转载

    StoredProcedure是一个抽象类,必须写一个子类来继承它,这个类是用来简化JDBCTemplate执行存储过程操作的. 首先我们写一个实现类: package com.huaye.frame ...

  8. Spring中ApplicationContextAware的用法

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt379 一.这个接口有什么用? 当一个类实现了这个接口(Application ...

  9. Spring中RedirectAttributes的用法

    RedirectAttributes 是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的的工具类.他有两种带参的方式: 第一种: redirectAttribut ...

随机推荐

  1. [Redis] - redis实战1

    rememberMe>>>>:null Creating a new SqlSession SqlSession [org.apache.ibatis.session.defa ...

  2. 说说Python中的闭包

    Python中的闭包不是一个一说就能明白的概念,但是随着你往学习的深入,无论如何你都需要去了解这么一个东西. 闭包的概念 我们尝试从概念上去理解一下闭包. 在一些语言中,在函数中可以(嵌套)定义另一个 ...

  3. zabbix回顾

    1.zabbix能收集哪些信息? 磁盘空间,磁盘IO,cpu负载,内存使用情况,开机时间,网卡的网络流量,进程数等 2.zabbix支持哪些通讯方式? agent:通过专用的代理程序进行监控,是mas ...

  4. Lintcode177-Convert Sorted Array to Binary Search Tree With Minimal Height-Easy

    177. Convert Sorted Array to Binary Search Tree With Minimal Height Given a sorted (increasing order ...

  5. ssm框架如果想要跨域请求,cors跨域

    <!-- 跨域 --> <mvc:cors> <mvc:mapping path="/**"/> </mvc:cors> 在spri ...

  6. 关于Ocelot和Consul 实现GateWay(网关) 服务注册 负载均衡等方面

    Ocelot   路由  请求聚合  服务发现 认证  鉴权 限流熔断 内置负载均衡器 Consul   自动服务发现    健康检查 通过Ocelot搭建API网关   服务注册   负载均衡 1. ...

  7. Eclipse下运行maven项目失败且Tomcat服务器也启动不了

    今天遇到一个神奇的问题,在eclipse中创建一个maven项目后,Run on server 时说服务器启动失败.我以为是Eclipse配置tomcat的问题.找了一大堆没找到想要的答案!!! 我还 ...

  8. 查看linux是ubuntu还是centos

    方式一: radhat或centos存在: /etc/redhat-release 这个文件[ 命令 cat /etc/redhat-release ] ubuntu存在 : /etc/lsb-rel ...

  9. 记录一下小程序canvas

    小程序canvas学习 效果图: .wxml <canvas style="width: 100vw; height: 100vh;" canvas-id="fir ...

  10. C++之标准库vector

    目录 1.成员函数 2.元素访问 3.迭代器iterator 4.容量capacity 5.修改函数 std::vector是一个封装动态数组的序列容器 std::pmr::vector是一个使用多态 ...