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的 ...
随机推荐
- 父级和 子集 controller 之间的通讯
在同个 angular.js 应用的控制器之间进行通信可以有很多种不同的方式,本文主要讲两种: 基于scope继承的方式 基于event传播的方式 基于scope继承的方式 最简单的让控制器之间进行通 ...
- ubuntu内部错误的解决办法
在ubuntu使用过程中,出现下面错误: 对不起,Ubuntu 16.04出现了内部错误. 这并不是ubuntu16.04特有的问题,好像每一个ubuntu版本都有类似的问题. 解决的办法有2个. 1 ...
- atitit. 文件上传带进度条 atiUP 设计 java c# php
atitit. 文件上传带进度条 atiUP 设计 java c# php 1. 设计要求 1 2. 原理and 架构 1 3. ui 2 4. spring mvc 2 5. springMVC.x ...
- atitit.安全的签名摘要 算法attilax总结
atitit.安全的签名 算法attilax总结 1. MD5 (不推荐)结果是128位二进制,只有转为16进制字符串是32位 1 2. 使用sha1算法加密后的密串长度有40位,相对更安全一些.Sh ...
- Netty的ByteBuf
https://blog.csdn.net/thinking_fioa/article/details/80795673 netty的ByteBuf知识点
- Cocos2d-x 3.x 如何编译成安卓程序
1.安装JDK 2.安装eclipse,安卓官方现在不提供eclipse for android,只好自己配置了.首先安装一个eclipse,在Help——Install New SoftWare中安 ...
- R ggplot2 翻转坐标
p <- ggplot(mpg, aes(class, hwy)) p + geom_boxplot() p + geom_boxplot() + coord_flip()
- Redis简单介绍
redis简单介绍 Redis VS key-value缓存产品 Redis支持数据的持久化,能够将内存中的数据保持在磁盘中,重新启动的时候能够再次载入进行使用. Redis不只支持简单的key-va ...
- EmWebAdmin 初步上手
EmWebAdmin 简介: // github 地址: https://github.com/ZengjfOS/EmWebAdmin // 介绍: 参考gentelella做的模板: 这是一个PHP ...
- qt 多点触摸
http://www.ptrackapp.com/apclassys-notes/embedded-linux-multitouch/ Embedded Linux Multitouch with Q ...