ApplicationListener自定义侦听器类
@Componentpublic class InstantiationTracingBeanPostProcessor implementsApplicationListener<ContextRefreshedEvent>{private static final Logger LOG = Logger.getLogger(InstantiationTracingBeanPostProcessor.class);private static booleaninitialized;@AutowiredprivateManageResolver manageResolver;@Overridepublic voidonApplicationEvent(ContextRefreshedEvent event) {try{//只在初始化“根上下文”的时候执行final ApplicationContext app =event.getApplicationContext();if (null ==app.getParent()&& ("Root WebApplicationContext".equals(app.getDisplayName())|| app.getDisplayName().contains("AnnotationConfigEmbeddedWebApplicationContext"))&& "/xweb".equals(app.getApplicationName())) {//当存在父子容器时,此判断很有用LOG.info("*************:" +event.getSource());LOG.info("*************:" +app.getDisplayName());LOG.info("*************:" +app.getApplicationName());LOG.info("*************:" +app.getBeanDefinitionCount());LOG.info("*************:" +app.getEnvironment());LOG.info("*************:" +app.getParent());LOG.info("*************:" +app.getParentBeanFactory());LOG.info("*************:" +app.getId());LOG.info("*************:" +app.toString());LOG.info("*************:" +app);if(!initialized && !manageResolver.IsInitialCompleted()) {manageResolver.initLater();initialized= true;}}}catch(Exception e) {LOG.error("((XmlWebApplicationContext) event.getSource()).getDisplayName() 执行失败,请检查Spring版本是否支持");}}}

SpringBoot应用程序启动类

@SpringBootApplication
@ImportResource({"classpath:config/applicationContext-xweb-dubbo.xml","classpath:config/applicationContext-xweb.xml"})
@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, RedisAutoConfiguration.class})public class XwebApplication extendsWebMvcConfigurerAdapter {public static voidmain(String[] args) {SpringApplication springApplication=new SpringApplication(XwebApplication.class);springApplication.addListeners(newInstantiationTracingBeanPostProcessor());springApplication.run(args);}/*** 上传附件容量限制*@return*/@BeanpublicMultipartConfigElement multipartConfigElement() {  MultipartConfigFactory factory= newMultipartConfigFactory();factory.setMaxFileSize("102400KB");  factory.setMaxRequestSize("112400KB");returnfactory.createMultipartConfig();  }/*** 配置拦截器*/@Overridepublic voidaddInterceptors(InterceptorRegistry registry) {//多个拦截器组成一个拦截器链//addPathPatterns 用于添加拦截规则//excludePathPatterns 用户排除拦截registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**");super.addInterceptors(registry);}}

转载于:https://www.cnblogs.com/cocoat/p/6513985.html

springboot + ApplicationListener相关推荐

  1. SpringBoot ApplicationListener监听器的使用-监听ApplicationReadyEvent事件

    SpringBoot监听器 ApplicationContext事件机制是观察者设计模式的实现,通过ApplicationEvent类和ApplicationListener接口,可以实现Applic ...

  2. springboot中使用ApplicationListener和ApplicationEvent /@EventListener监听事件

    文章目录 自定义一个事件类 监听类: 事件发布者 改用@EventListener注解: 总结 自定义一个事件类 public class OnRegistrationCompleteEvent ex ...

  3. SpringBoot:ApplicationEvent与ApplicationListener

    1.美图 2.概述 Spring的世界中有这么一对好基友,两个人总是同时出现,相爱相杀.这就是ApplicationEvent与ApplicationListener.感觉有点像小偷和警察,只要App ...

  4. 非常有必要了解的Springboot启动扩展点

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 来源:r6d.cn/r4P7 背景 Spring的核心思想 ...

  5. 这样讲 SpringBoot 自动配置原理,你应该能明白了吧

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试资料 作者:你在我家门口 juejin.im/post/5ce5effb ...

  6. Springboot启动原理解析

    点击上方"方志朋",选择"置顶公众号" 技术文章第一时间送达! 我们开发任何一个Spring Boot项目,都会用到如下的启动类 @SpringBootAppl ...

  7. SpringBoot数据访问配置

    文章目录 一.简介 二.特性 三.主要模块 四.SpringBoot整合基本JDBC与数据源 SpringBoot整合JDBC SpringBoot整合Druid数据源 一.简介 对于数据访问层而言, ...

  8. 六种方式,教你在SpringBoot初始化时搞点事情!

    前言 在实际工作中总是需要在项目启动时做一些初始化的操作,比如初始化线程池.提前加载好加密证书....... 那么经典问题来了,这也是面试官经常会问到的一个问题:有哪些手段在Spring Boot 项 ...

  9. 手把手带你剖析 Springboot 启动原理!

    作者:平凡希 cnblogs.com/xiaoxi/p/7999885.html 我们开发任何一个Spring Boot项目,都会用到如下的启动类 @SpringBootApplication pub ...

最新文章

  1. MCMC笔记:吉布斯采样(Gibbs)
  2. 进入保护模式(四)设置一些公用的方法
  3. JavaScript中十个一步拷贝数组的方法
  4. Python pandas模块输出每行中间省略号问题
  5. 如何实现 asp.net core 安全优雅退出 ?
  6. [vue] 你是从vue哪个版本开始用的?你知道1.x和2.x有什么区别吗?
  7. dhcp服务器能为客户端提供哪些信息,为DHCP客户端提供DHCP服务器的MAC [关闭]
  8. 工具资源系列之给虚拟机装个windows
  9. 【转】Golang 关于通道 Chan 详解
  10. cron每月1号_微信服务号按粉丝标签分组群发消息怎样实现?
  11. SAP License:CO-第四夜-产品成本核算
  12. openshift启动失败
  13. [2178]链表的有序集合 (链表的插排法+重复元素的删除) SDUT
  14. 639. 解码方法 2
  15. 【时间序列分析】02. 线性平稳序列
  16. 最简单!阿里云服务器采用 LNMP一键安装包 配置 Linux+Nginx+Mysql+PHP
  17. linux图片转成pdf文件大小,Linux下实现图片转pdf以及pdf转图片的命令_沃航科技
  18. ID7S625高压逆变器驱动芯片
  19. 《模式识别》期末考试考题汇总带答案
  20. 访问html 403 iis,IIS 403 错误详细原因 及解决办法总结

热门文章

  1. 第一阶段 XHTML.定位样式
  2. Spring+jpaNo transactional EntityManager available
  3. VueJs学习入门指引
  4. elasticsearch,elasticsearch-service安装
  5. CentOS7 Firewall NAT 及端口映射
  6. 手把手教你 Spark 性能调优
  7. 《C专家编程》一1.6 它很棒,但它符合标准吗
  8. Ubuntu10.04制作官方源镜像以及搭建本地源
  9. AT91RM9200Linux移植笔记(三)-移植Linux kernel 2.6.17
  10. 数据冒险控制冒险_劳动生产率和其他冒险