package com.chinacreator.video.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringContextUtil implements ApplicationContextAware
{
    private static ApplicationContext applicationContext;
    
    public static ApplicationContext getApplicationContext() {
        return SpringContextUtil.applicationContext;
    }
    
    public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.applicationContext = applicationContext;
    }
    
    public static Object getBean(final String name) {
        return SpringContextUtil.applicationContext.getBean(name);
    }
    
    public static <T> T getBean(final Class<T> clazz) {
        return (T)SpringContextUtil.applicationContext.getBean((Class)clazz);
    }
}
