springboot + ApplicationListener
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的更多相关文章
- 【ApplicationListener】Springboot各类事件监听器
Springboot中SpringApplicationEvent的种类 如下图: 主要包括6种: ApplicationEnvironmentPreparedListener Application ...
- SpringBoot常用配置简介
SpringBoot常用配置简介 1. SpringBoot中几个常用的配置的简单介绍 一个简单的Spring.factories # Bootstrap components org.springf ...
- 深入SpringBoot:自定义PropertySourceLoader
http://www.jianshu.com/p/5206f74a4406 ********************************* 前言 上一篇文章介绍了SpringBoot的Enable ...
- springboot源码解析 - 构建SpringApplication
1 package com.microservice.framework; 2 3 import org.springframework.boot.SpringApplication; 4 impor ...
- SpringBoot Quickstart
SpringBoot Intro SpringBoot是顺应现在微服务(MicroServices)理念而产生的一个微框架(同类微框架可供选择的还有Dropwizard), 用来构建基于Spring框 ...
- springboot 开发入门,及问题汇总
1 . springboot简单介绍(http://projects.spring.io/spring-boot/) 现在的web项目几乎都会用到spring框架,而要使用spring难免需要配置大量 ...
- Springboot启动源码详解
我们开发任何一个Spring Boot项目,都会用到如下的启动类 @SpringBootApplication public class Application { public static voi ...
- Springboot基础篇
Springboot可以说是当前最火的java框架了,非常适合于"微服务"思路的开发,大幅缩短软件开发周期. 概念 过去Spring充满了配置bean的xml文件,随着spring ...
- SpringBoot运行原理
如果我们使用的是SpringApplication的静态run方法,那么,这个方法里面首先要创建一个SpringApplication对象实例,然后调用这个创建好的SpringApplication的 ...
随机推荐
- Objective-c的@property 详解
转自:http://www.cnblogs.com/andyque/archive/2011/08/03/2125728.html 之前很多网友对我翻译的教程中的Property的使用感到有些迷惑不解 ...
- android线程控制UI更新(Handler 、post()、postDelayed()、postAtTime)
依照以下的理解就是handler与ui线程有一定的关联能够由于更新界面仅仅能在主线程中全部更新界面的地方能够在接受消息的handleMessage那里还有更新界面能够在handler.port(new ...
- 419. Roman to Integer【medium】
Given a roman numeral, convert it to an integer. The answer is guaranteed to be within the range fro ...
- dp之完全背包poj2063
题意:求投资k年获得最大投资,每年都选最大利息的方案进行投资k年后就可以得到最多的人民币. 注意:每一年收到的利息都可以作为下一年的本金......其实从测试数据来看,是很好看出来的...... 思路 ...
- C语言 · 复数四则运算
算法提高 6-17复数四则运算 时间限制:1.0s 内存限制:512.0MB 设计复数库,实现基本的复数加减乘除运算. 输入时只需分别键入实部和虚部,以空格分割,两个复数之间用运算符 ...
- STM32CubeMX使用方法及功能介绍
推荐 分享一个朋友的人工智能教程,零基础!通俗易懂!希望你也加入到人工智能的队伍中来! http://www.captainbed.net/strongerhuang Ⅰ.写在前面 学习本文之前可以查 ...
- JS 数组以及对象的深拷贝总结
javascript 数组以及对象的深拷贝(复制数组或复制对象)的方法 前言 在js中,数组和对象的复制如果使用=号来进行复制,那只是浅拷贝.如下图演示: 如上,arr的修改,会影响arr2的值,这 ...
- 概率dp - UVA 11021 Tribles
Tribles Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059 Mean: 有k个细 ...
- java 多线程 1 “常用的实现多线程的2种方式”:Thread 和 Runnable
转载系列自http://www.cnblogs.com/skywang12345/p/java_threads_category.html 当使用第一种方式(继承Thread的方式)来生成线程对象时, ...
- 【BZOJ】1052: [HAOI2007]覆盖问题(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1052 首先膜拜题解orz,表示只能想到二分... 贪心就是每一次找到一个最小的能包围所有点的矩阵,然 ...