package component.spring;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.ContextStoppedEvent;

public class SpringApplicationEventListner implements ApplicationListener  {
    private static Log log = LogFactory.getLog(SpringApplicationEventListner.class);
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ContextStartedEvent){
            log.info("**** SPRING CYCLE: CONTEXT_STARTED ****");
        }else if (event instanceof ContextStoppedEvent){
            log.info("**** SPRING CYCLE: CONTEXT_STOPPED ****");
        }else if (event instanceof ContextRefreshedEvent){
            log.info("**** SPRING CYCLE: CONTEXT_REFRESHED ****");
        }else if(event instanceof ContextClosedEvent){
            log.info("**** SPRING CYCLE: CONTEXT_CLOSED ****");
        }else{
            log.info("**** SPRING EVENT: " + event.toString() + " ****");
        }
    }
}
