美文网首页
容器上下文事件

容器上下文事件

作者: 充满智慧的白痴 | 来源:发表于2019-12-30 10:29 被阅读0次
// 定义开始事件
package com.tutorialspoint;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStartedEvent;
public class CStartEventHandler 
   implements ApplicationListener<ContextStartedEvent>{
   public void onApplicationEvent(ContextStartedEvent event) {
      System.out.println("ContextStartedEvent Received");
   }
}
// 定义一个context结束时间
package com.tutorialspoint;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStoppedEvent;
public class CStopEventHandler 
   implements ApplicationListener<ContextStoppedEvent>{
   public void onApplicationEvent(ContextStoppedEvent event) {
      System.out.println("ContextStoppedEvent Received");
   }
}
// 容器注入事件对象
 <bean id="cStartEventHandler" class="com.tutorialspoint.CStartEventHandler"/>
 <bean id="cStopEventHandler" class="com.tutorialspoint.CStopEventHandler"/>
 ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
 context.start();
 context.stop();
 context.close();

自定义事件

相关文章

网友评论

      本文标题:容器上下文事件

      本文链接:https://www.haomeiwen.com/subject/qyfqpctx.html