All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xin.alum.aim.util.ApplicationContextUtil Maven / Gradle / Ivy

There is a newer version: 1.9.6
Show newest version
package xin.alum.aim.util;

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

@Component
public class ApplicationContextUtil implements ApplicationContextAware {

    private static ApplicationContext Context;

    /**
     * 获取bean
     *
     * @param name
     * @return
     * @throws BeansException
     */
    public static Object getBean(String name) throws BeansException {
        return Context.getBean(name);
    }

    public static  T getBean(Class c) throws BeansException {
        return Context.getBean(c);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextUtil.Context = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return Context;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy