在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

springboot获取上下文ApplicationContext的更多相关文章

  1. 如何获取SpringBoot项目的applicationContext对象

    ApplicationContext对象是Spring开源框架的上下文对象实例,在项目运行时自动装载Handler内的所有信息到内存.传统的获取方式有很多种,不过随着Spring版本的不断迭代,官方也 ...

  2. springboot获取applicationcontext

    使用springboot之前,我们通过ClassPathXmlApplicationContext加载spring xml配置文件来获取applicationcontext,使用springboot后 ...

  3. quartz 的job中获取到applicationContext

    第一步: 定义SchedulerFactoryBean的applicationContextSchedulerContextKey <bean name="scheduler" ...

  4. 【spring框架】spring获取webapplicationcontext,applicationcontext几种方法详解--(转)

    方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXmlApplicationContext(" ...

  5. 使用Arthas 获取Spring ApplicationContext还原问题现场

    ## 背景 最近来了个实习僧小弟,安排他实现对目标网站 连通性检测的小功能,简单讲就是将下边的shell 脚本换成Java 代码来实现 ``` 1#!/bin/bash 2URL="http ...

  6. 如何在Job中获取 IOC applicationcontext

    如何在Job中获取 IOC applicationcontext https://segmentfault.com/q/1010000008002800 SpringBoot之整合Quartz调度框架 ...

  7. 死磕Spring之IoC篇 - Spring 应用上下文 ApplicationContext

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...

  8. @PostConstruct +getapplicationcontext.getbean springboot获取getBean

    Componentpublic class SpringContextUtils implements ApplicationContextAware { public static Applicat ...

  9. 前后台获取上下文context

    1.web server端获取上下文:Context ctx = WafContext.getInstance().getContext();上下文中包含当前登录组织.当前登录用户.语种.数据库.客户 ...

随机推荐

  1. Vue --- 指令练习

    scores = [ { name: 'Bob', math: 97, chinese: 89, english: 67 }, { name: 'Tom', math: 67, chinese: 52 ...

  2. Django API接口FK ManyTo Many 模板

    Url from django.contrib import admin from django.urls import path, re_path from django.urls import i ...

  3. go 学习 (五):包管理

    一.设置环境变量 二.启用 go modules 功能 并设置代理 https://goproxy.io/zh/ 补充: GO111MODULE  有三个值:on.off.auto GO111MODU ...

  4. yolov1详细讲解

    前言 当我们谈起计算机视觉时,首先想到的就是图像分类,没错,图像分类是计算机视觉最基本的任务之一,但是在图像分类的基础上,还有更复杂和有意思的任务,如目标检测,物体定位,图像分割等,见图1所示.其中目 ...

  5. tldr/cheat

    tldr 比man好用的查询命令查询工具, man很强大,但是 TLDR,too long dont read 安装 npm install -g tldr 使用说明 其他版本下载 https://g ...

  6. 洛谷 P2918 [USACO08NOV]买干草Buying Hay 题解

    P2918 [USACO08NOV]买干草Buying Hay 题目描述 Farmer John is running out of supplies and needs to purchase H ...

  7. last-child为啥不生效

    last-child基本定义 指定属于其父元素的最后一个子元素的 p 元素的背景色 如果你这样写是不会生效的 <div class="limit-border"> &l ...

  8. 帝国cms更换Ueditor编辑器上传图片加水印

    Ueditor安装包,里面有个/php/文件夹,找到Uploader.class.php,这是通用上传类文件找到private function upFile(),这是上传文件的主处理方法,找到122 ...

  9. 坑爹微信之读取PKCS12流时出现的java.io.IOException: DerInputStream.getLength

    背景 微信退款接口需要使用到证书,我参考微信的官方Demo进行,部分代码如下: char[] password = config.getMchID().toCharArray(); InputStre ...

  10. python selenium chrome 实现自动化登录

    1.环境安装 selenium的开发文档网址(英语好的可以直接看这个,写的很详细):http://selenium-python.readthedocs.io/ 因为实现的时候使用的是谷歌浏览器,在运 ...