类org.springframework.boot.context.event.SpringApplicationEvent源码实例Demo

下面列出了怎么用org.springframework.boot.context.event.SpringApplicationEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: sofa-ark   文件: ArkApplicationStartListener.java
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
    try {
        if (isSpringBoot2()
            && APPLICATION_STARTING_EVENT.equals(event.getClass().getCanonicalName())) {
            startUpArk(event);
        }

        if (isSpringBoot1()
            && APPLICATION_STARTED_EVENT.equals(event.getClass().getCanonicalName())) {
            startUpArk(event);
        }
    } catch (Throwable e) {
        throw new RuntimeException("Meet exception when determine whether to start SOFAArk!", e);
    }
}
 
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
	System.out.println("SpringApplicationEvent Received - " + event);

	// Initializing publisher for custom event
	this.initPublisher(event);
}
 
@EventListener({ApplicationReadyEvent.class, ApplicationFailedEvent.class})
public void onSpringBootEvent(SpringApplicationEvent event) {
    System.out.println("@EventListener 监听到事件 : " + event.getClass().getSimpleName());
}
 
源代码4 项目: sofa-ark   文件: ArkApplicationStartListener.java
public void startUpArk(SpringApplicationEvent event) {
    if (LAUNCH_CLASSLOADER_NAME.equals(this.getClass().getClassLoader().getClass().getName())) {
        SofaArkBootstrap.launch(event.getArgs());
    }
}
 
private void initPublisher(SpringApplicationEvent event) {
	if (event instanceof ApplicationReadyEvent) {
		this.applicationContext.getBean(Publisher.class).publishEvent();
	}
}
 
 类所在包
 类方法
 同包方法