BAEL-1782

This commit is contained in:
Tritty 2018-08-25 20:44:53 +05:30
parent fee82e2211
commit 1eca2b5c79
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package com.baeldung.event.listener;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
public class ContextEventListener {
@Order(2)
@EventListener
public void handleContextRefreshEvent(ContextStartedEvent ctxStartEvt) {
System.out.println("Context Start Event received.");
}
@Order(1)
@EventListener(classes = { ContextStartedEvent.class, ContextStoppedEvent.class })
public void handleMultipleEvents() {
System.out.println("Multi-event listener invoked");
}
}

View File

@ -0,0 +1,10 @@
package com.baeldung.event.listener;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = "com.baeldung.event.listener")
public class EventConfig {
}

View File

@ -0,0 +1,12 @@
package com.baeldung.event.listener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class SpringRunner {
public static void main(String[] args) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(EventConfig.class);
ctx.start();
}
}