ApplicationContext events have never been thrown

I try to have ContextEventListenerContextXXXEvent for all. I created a listener for each type of event as follows ( ContextRefreshedEvent- example):

@Component
public class MyApplicationRefreshedListener implements ApplicationListener<ContextRefreshedEvent> {

  @Override
  public void onApplicationEvent(ContextRefreshedEvent event) {
    logger.info(getClass(), "Event source [{}]", event.getSource());
  }

}

Both ContextRefreshedEventand ContextClosedEventwere caught, and their students carried out the expected performance.

I tried to do the same for ContextStartedEventand ContextClosedEvent, but both of these events were not caught.

Printed event.getSource(in updated and closed events):

Event source [Root WebApplicationContext: startup date [Tue May 09 10:07:51 IDT 2017]; root of context hierarchy]

Is there a difference between (start and end) and (updated and closed)?

This is because my application context WebApplicationContext(as shows event.getSource()?)

+6
source share
1 answer

spring . ContextStartedEvent. .

:

ContextStartedEvent start() AbstractApplicationContext . ContextStartedEvent, , , .

spring, applicationContext . -, start(), beans . - spring - . , start stop . . , xml bean, ClassPamlApplicationContext. AbstractRefreshableApplicationContext.

, , ContextStartedEvent ContextStoppedEvent , () ApplicationContext . ApplicationContext, ApplicationContext . . , .

ContextStoppedEvent.

. , spring ( by @coolgirl)

+1

Source: https://habr.com/ru/post/1017095/


All Articles