ApplicationReadyEvent

ApplicationReadEvent

事件的来源是SpringApplication,事件发生时,所有的初始化步骤都已经完成。

用法

1
2
3
4
5
6
7
8
9
10
11
12
13
@Component
public class ApplicationReadyEventListener implements ApplicationListener<ApplicationReadyEvent>, Ordered {

@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
System.out.println("############started");
}

@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
}

配合EventListener使用

1
2
3
4
5
6
7
8
@Component
class MyClassWithEventListeners {

@EventListener({ApplicationReadyEvent.class})
void contextRefreshedEvent() {
System.out.println("event happened");
}
}