1 4 5 package com.tctest.spring.bean; 6 7 import org.springframework.context.ApplicationEvent; 8 import org.springframework.context.ApplicationListener; 9 10 import java.util.ArrayList ; 11 import java.util.Date ; 12 import java.util.List ; 13 14 15 public class SimpleListener implements ApplicationListener { 16 private transient List events = new ArrayList (); 17 private Date lastEventTime; 18 19 public List getEvents() { 20 return this.events; 21 } 22 23 25 public void onApplicationEvent(ApplicationEvent event) { 26 if(event instanceof SingletonEvent) { 27 System.out.println("Got SingletonEvent: " + event); 28 this.events.add(event); 29 this.lastEventTime = new Date (); 30 } else { 31 System.out.println("Got some other kind of event: " + event); 32 } 33 } 34 35 public Date getLastEventTime() { 36 return lastEventTime; 37 } 38 } 39 40 | Popular Tags |