下面列出了org.springframework.boot.context.event.ApplicationFailedEvent#org.springframework.boot.context.event.SpringApplicationEvent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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());
}
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();
}
}