springboot获取上下文ApplicationContext

摘要:
在springboot主程序中,将其更改为publicstatic void main(String[]args){//SpringApplication.run(SpringbootAPP.class,args);将其更改成SpringApplicationsa=newSpringApplication(SpringbootAPP.class);sa.addListeners(newMainBusiList

在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》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Linux patch命令详解Java泛型详解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

json(转)

例如:varjsonObj={StudentID:“100”,名称:“tmac”,家乡:“usa”};回到顶部,如何在JS中使用JSON是JS的一个子集,因此您可以轻松地在JS中读写JSON。例如,现在我们有一个TStudent的学生表。表中的字段和现有数据如图所示。从表中,我们可以看到总共五条数据。现在我们需要从数据库中获取这些数据,然后使用JSON.NE...

UOS怎么访问windows共享的文件夹

至此就共享成功了如何查看一个文件夹的绝对路径双击打开UOS桌面中的winshare文件夹,右键点击在终端中打开然后再输入pwd,记住这个路径,这个就是UOS中这个目录的绝对路径了...

微信小程序中使用Vant Weapp的ActionSheet上拉菜单出现的样式问题

以下修改的源码均在action-sheet组件中。在index.wxss:2.下方的取消按钮不居中,通过审查元素发现它的宽带已经超出了手机屏幕的宽度,出现的滚动条导致的,具体什么原因导致暂时不知,解决方案是给.van-action-sheet__cancel添加样式box-sizing:border-box可解决。在index.wxss:.van-actio...

eventUtil

}elseif(element.attachEvent){element.aattchEvent('on'+类型,}else{element['on'+type]=处理程序;}else{element['on'+类型]=null;函数(事件){returnevent.type;}否则{event.returnValue=false;...

Qt中使用定时器(可使用QObject::timerEvent定时执行,QTimer::singleShot可只触发一次)

在Qt中使用定时器有两种方法,一种是使用QObiect类的定时器;一种是使用QTimer类。当定时器触发时,应用程序会发送一个QTimerEvent。与定时器相关的成员函数有:startTimer()、timeEvent()、killTimer()。virtualvoidQObject::timerEvent;虚函数timerEvent()被重载来实现用户的...

(二)Jenkins配置主从节点实例

4.从节点配置和相关配置中从节点机创建jenkins用户,并从一些环境配置中创建jenkings用户的ssh密钥,用于指定上述配置界面的ssh启动模式;在配置启动模式和项目源代码管理中从远程仓库获取源代码;创建Jenkins用户并使用root登录到远程子节点计算机。#adduserjenkins#passwdjenkins生成Jenkins用户的ssh密钥。...