标签:amp nap get res lang frame 监听 list rhel
利用 Spring 工厂加载机制,实例化 ApplicationListener 实现类,并排序对象集合
@Order(Ordered.HIGHEST_PRECEDENCE)
public class HelloWorldApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
System.out.println("HelloWorld : " + event.getApplicationContext().getId()
+ " , timestamp : " + event.getTimestamp());
}
}
public class AfterHelloWorldApplicationListener implements ApplicationListener<ContextRefreshedEvent>,Ordered {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
System.out.println("AfterHelloWorld : " + event.getApplicationContext().getId()
+ " , timestamp : " + event.getTimestamp());
}
@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
}
# ApplicationListener
org.springframework.context.ApplicationListener=com.imooc.diveinspringboot.listener.AfterHelloWorldApplicationListener,com.imooc.diveinspringboot.listener.HelloWorldApplicationListener,
HelloWorld : application , timestamp : 1591105193644
AfterHelloWorld : application , timestamp : 1591105193644
标签:amp nap get res lang frame 监听 list rhel
原文地址:https://www.cnblogs.com/fjf3997/p/13035875.html