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. API 版本控制的几种方式

    个人建议:用content type,即放在Header里面!比如加一个Version:1.4.3 这篇文章写得很好,介绍了三种实现web api版本化的三种方式.我从评论里又收集到两种方式,所以一共 ...

  2. [ukulele]入门指南

    不少尤克里里初学者在开始学习尤克里里的时候,都会进行尤克里里教程搜索,还有不少新手会问“尤克里里和吉他的区别”“尤克里里好学吗”“尤克里里和弦有哪些”等问题.今天,国际知名乐器品牌Gorilla歌芮拉 ...

  3. Struts2的OGNL遍历数组、List、简单的Map

    一.简介 <s:iterator />可以遍历 数据栈里面的任何数组,集合等等 在使用这个标签的时候有三个属性值得我们关注      1. value属性:可选的属性,value属性是指一 ...

  4. Java并发之彻底搞懂偏向锁升级为轻量级锁

    网上有许多讲偏向锁,轻量级锁的文章,但对偏向锁如何升级讲的不够明白,有些文章还相互矛盾,经过对jvm源码(biasedLocking.cpp)的仔细分析和追踪,基本升级过程有了一个清晰的过程,现将升级 ...

  5. xadmin 问题总结

    pip install django-import-export

  6. cf 459c Pashmak and Buses

    E - Pashmak and Buses Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  7. AndroidStudio添加Android源码

    找了半天没找到,还是用google好啊!修改如下,打开如下的build.gradle,修改compileSdkVersion 为你下载的源码版本号. Open your sdk manager fro ...

  8. Eclipse中安装JBoss Tools插件

    1.先访问JBoss Tools网站,看看上面怎么说: http://tools.jboss.org -> 进入下载界面 看到下面这句话: Drag and drop this  icon in ...

  9. Android——Activity中的六个主要函数

    Android Activity中的六个主要函数 Android中一个Activity一般都需要实现六个函数: onCreate(), onStart(), onResume(),onPause(), ...

  10. C++ 引用本质的详解

    //引用本质的理解① #include<iostream> using namespace std; int GetA(){ ; return a; } int & GetB(){ ...