xin.alum.aim.util.ApplicationContextUtil Maven / Gradle / Ivy
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;
}
}