BAEL-1782
This commit is contained in:
parent
fee82e2211
commit
1eca2b5c79
@ -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");
|
||||
}
|
||||
|
||||
}
|
@ -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 {
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user