在springboot主程序里改成

public static void main(String[] args) {
// SpringApplication.run(SpringbootAPP.class, args);换成下面
SpringApplication sa = new SpringApplication(SpringbootAPP.class);
sa.addListeners(new MainBusiListeners());
sa.run(args);
}
package com.xxx.xxxx;

import com.xxx.utils.SpringContextUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent; /**
* 启动监听
*/
public class MainBusiListeners implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
SpringContextUtils.setApplicationContextByMain(event.getApplicationContext());
}
}
@Component
public class SpringContextUtils { private static ApplicationContext applicationContext; public static void setApplicationContextByMain(ApplicationContext applicationContext) {
if (SpringContextUtils.applicationContext == null) {
SpringContextUtils.applicationContext = applicationContext;
}
}

参考文章:https://www.cnblogs.com/qq931399960/p/10184151.html

最新文章

  1. ndk学习16: unix domain socket
  2. bc.34.B.Building Blocks(贪心)
  3. 仿php的日期函数,asp时间处理函数
  4. char*与char[]
  5. 从Chrome源码看浏览器的事件机制
  6. react-router 离开路由前确认
  7. springboot~Money类型在序列化时遇到的问题与解决
  8. Linux下利用文件描述符恢复的成功失败实验
  9. LeetCode算法题-Implement Stack Using Queues
  10. Individual Project 1 总结
  11. Java过滤器Filter的使用详解
  12. 转 c#中stringbuilder的使用
  13. JS 判断object是否包含某个键
  14. elast alert
  15. spfa 单源最短路究极算法
  16. ASP.NET MVC4企业级实战目录
  17. js在一个可编辑的div光标处插入图片或者文本(兼容ie,火狐等浏览器)
  18. (转)Memcached 之 .NET(C#)实例分析
  19. malloc与free函数用法
  20. java算法 蓝桥杯算法训练 Fibonacci数列

热门文章

  1. AST11103 Problem Solving
  2. 目标检测中的bounding box regression
  3. python的多线程是否没有用了
  4. web自动化测试-模块驱动测试实例和数据驱动测试实例
  5. reshape()函数
  6. 如何调试 Windows 服务
  7. vue-router 的两种模式的区别
  8. 点击复制文字到剪贴板兼容性安卓ios
  9. 了解Python-白 驹 过 隙 , 忽 然 而 已
  10. .getCellType()的几种类型值