package com.ag.dynamicmodule.main;

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

/**
 * Created by yangxh on 2019/8/12.
 */
@Component
public class HotApplicationContext implements ApplicationContextAware {
    private static ApplicationContext appContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        appContext = applicationContext;
    }

    public static Object getBean(String beanName) {
        return appContext.getBean(beanName);
    }

    public static <T> Object getBean(Class<T> c) {
        return appContext.getBean(c);
    }

    public static boolean isContainsMain(String beanName){
        return appContext.containsBeanDefinition(beanName);
    }

    public static Boolean containsBean(String beanName){
        return appContext.containsBean(beanName);
    }

    public static String[] findAllBeans(){
        return appContext.getBeanDefinitionNames();
    }
}
