ApplicationListener自定义侦听器类

@Component
public class InstantiationTracingBeanPostProcessor implements
ApplicationListener<ContextRefreshedEvent> {
private static final Logger LOG = Logger.getLogger(InstantiationTracingBeanPostProcessor.class);
private static boolean initialized; @Autowired
private ManageResolver manageResolver; @Override
public void onApplicationEvent(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 extends WebMvcConfigurerAdapter { public static void main(String[] args) {
SpringApplication springApplication =new SpringApplication(XwebApplication.class);
springApplication.addListeners(new InstantiationTracingBeanPostProcessor());
springApplication.run(args);
} /**
* 上传附件容量限制
* @return
*/
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("102400KB");
factory.setMaxRequestSize("112400KB");
return factory.createMultipartConfig();
} /**
* 配置拦截器
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 多个拦截器组成一个拦截器链
// addPathPatterns 用于添加拦截规则
// excludePathPatterns 用户排除拦截
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**");
super.addInterceptors(registry);
} }

springboot + ApplicationListener的更多相关文章

  1. 【ApplicationListener】Springboot各类事件监听器

    Springboot中SpringApplicationEvent的种类 如下图: 主要包括6种: ApplicationEnvironmentPreparedListener Application ...

  2. SpringBoot常用配置简介

    SpringBoot常用配置简介 1. SpringBoot中几个常用的配置的简单介绍 一个简单的Spring.factories # Bootstrap components org.springf ...

  3. 深入SpringBoot:自定义PropertySourceLoader

    http://www.jianshu.com/p/5206f74a4406 ********************************* 前言 上一篇文章介绍了SpringBoot的Enable ...

  4. springboot源码解析 - 构建SpringApplication

    1 package com.microservice.framework; 2 3 import org.springframework.boot.SpringApplication; 4 impor ...

  5. SpringBoot Quickstart

    SpringBoot Intro SpringBoot是顺应现在微服务(MicroServices)理念而产生的一个微框架(同类微框架可供选择的还有Dropwizard), 用来构建基于Spring框 ...

  6. springboot 开发入门,及问题汇总

    1 . springboot简单介绍(http://projects.spring.io/spring-boot/) 现在的web项目几乎都会用到spring框架,而要使用spring难免需要配置大量 ...

  7. Springboot启动源码详解

    我们开发任何一个Spring Boot项目,都会用到如下的启动类 @SpringBootApplication public class Application { public static voi ...

  8. Springboot基础篇

    Springboot可以说是当前最火的java框架了,非常适合于"微服务"思路的开发,大幅缩短软件开发周期. 概念 过去Spring充满了配置bean的xml文件,随着spring ...

  9. SpringBoot运行原理

    如果我们使用的是SpringApplication的静态run方法,那么,这个方法里面首先要创建一个SpringApplication对象实例,然后调用这个创建好的SpringApplication的 ...

随机推荐

  1. eclipse中maven插件,改变默认仓库位置

    一.eclipse中maven默认仓库是当前用户下.m2/repository,需改变默认路径按照下面步骤. 步骤一:安装maven 下载:http://maven.apache.org/ 配置mav ...

  2. javascript递归、循环、迭代、遍历和枚举概念

    javascript递归.循环.迭代.遍历和枚举概念 〓递归(recursion)在数学与计算机科学中,是指在函数的定义中使用函数自身的方法.递归一词还较常用于描述以自相似方法重复事物的过程.例如,当 ...

  3. zend server 和zend studio 最佳实践

    1.zend server 安装好后需要重启下.无论是win还是mac..win不重启组件不能用.mac 不重启守护进程是离线的 2.修改apache配置.的根目录.到zendstudio的工作空间 ...

  4. 效果非常好的 Jquery弹出层插件 jQuery Sweet alert

    介绍款交互性非常不错的jquery弹出层插件,支持消息提示.错误提示.确认框提示等. 交互式体验感非常不错,比如咱们现在体验非常不错的微信支付.支付宝等完成后的效果. 不过本插件至少支持IE9+ Jq ...

  5. layui的点击table行选中复选框

    $(document).on("click",".layui-table-body table.layui-table tbody tr",function() ...

  6. jsp学习之scriptlet的使用方法

    scriptlet的使用 jsp页面中分三种scriptlet: 第一种:<%  %>  可以在里面写java的代码.定义java变量以及书写java语句. 第二种:<%! %> ...

  7. background-origin:规定 background-position 属性相对于什么位置来定位

    background-origin:border-box;此时设置background-size:contain; 根据容器的边框定位 例如:容器的盒模型如下:设置了padding:20px;bord ...

  8. RP2837 OUT1-OUT2 对应关系 2路DO

    RP2837 OUT1-OUT2 对应关系: OUT1  AD2   PD22  继电器1 OUT2  AD4   PD24     继电器2 root@sama5d3-linux:~ echo 11 ...

  9. 使用shell读取文本文件发送到kafka

    #!/bin/sh ## 参数定义 dt=`date +"%Y%m%d" -d "-1 days"` outpath=/xxxx_log_${dt}.txt b ...

  10. (转)maven3.3.9编译oozie4.3.0

    1.Java版本1.8 [root@sht-sgmhadoopdn-04 app]# java -versionjava version "1.8.0_66"Java(TM) SE ...