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的 ...
随机推荐
- Cookie/Session编码
Unicode编码:保存中文 中文与英文字符不同,中文属于Unicode字符,在内存中占4个字符,而英文属于ASCII字符,内存中只占2个字节.Cookie中使用Unicode字符时需要对Unicod ...
- spring session配置
spring session是一个解决集群环境中,session持久化管理的依赖库.配置非常简单. 在spring boot环境中添加依赖 <dependency> <groupId ...
- C++虚函数解析(转载)
虚函数详解第一篇:对象内存模型浅析 C++中的虚函数的内部实现机制到底是怎样的呢? 鉴于涉及到的内容有点多,我将分三篇文章来介绍. 第一篇:对象内存模型浅析,这里我将对对象的内存模型进 ...
- js delete
在开始之前,先让我们看一段代码 >>> var sum = function(a, b) {return a + b;} >>> var add = sum; &g ...
- 单调栈poj2796
题意:给你一段区间,需要你求出(在这段区间之类的最小值*这段区间所有元素之和)的最大值...... 例如: 6 3 1 6 4 5 2 以4为最小值,向左右延伸,6 4 5 值为60....... ...
- matlab_legend_使用
matlab legend 使用 用Matlab画图时,有时候需要对各种图标进行标注,例如,用“+”代表A的运动情况,“*”代表B的 运动情况.legend函数的基本用法是LEGEND(string1 ...
- 股票指数kdj,sar,macd
http://blog.eastmoney.com/gulingqianketong2011/blog_120832611.html http://blog.sina.com.cn/s/blog_a3 ...
- 怎么隐藏MathType标尺
因为MathType公式编辑能力非常的好用,所以非常的受大家的欢迎.MathType用现有的模板可以直接输入输出各种公式,而且MathType中有着各式各样的数学符号满足了大家日常公式的需求,为大家的 ...
- Sublime Text2.0.2注冊码
// Sublime Text 3 License Keys // Sublime Text 2.x -– BEGIN LICENSE -– Andrew Weber Single User Lice ...
- HttpModule,HttpContext,HttpHandler
http://www.cnblogs.com/wujy/tag/ASP.NET%E5%9F%BA%E7%A1%80/ http://www.th7.cn/Program/net/2011/12/26/ ...