package cn.com.qmth.archive.utils; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.ResolvableType; import org.springframework.stereotype.Component; /** * spring context holder. * */ @Component public class SpringContextHolder implements ApplicationContextAware { private static ApplicationContext ctx = null; @Override public void setApplicationContext(ApplicationContext ctx) { SpringContextHolder.ctx = ctx; } public static ApplicationContext getApplicationContext() { return ctx; } public static Object getBean(String name) { return ctx.getBean(name); } public static T getBean(String name, Class requiredType) { return ctx.getBean(name, requiredType); } public static T getBean(Class requiredType) { return ctx.getBean(requiredType); } public static Object getBean(String name, Object... args) { return ctx.getBean(name, args); } public static T getBean(Class requiredType, Object... args) { return ctx.getBean(requiredType, args); } public static boolean containsBean(String name) { return ctx.containsBean(name); } public static boolean isSingleton(String name) { return ctx.isSingleton(name); } public static boolean isPrototype(String name) { return ctx.isPrototype(name); } public static boolean isTypeMatch(String name, ResolvableType typeToMatch) { return ctx.isTypeMatch(name, typeToMatch); } public static boolean isTypeMatch(String name, Class typeToMatch) { return ctx.isTypeMatch(name, typeToMatch); } public static Class getType(String name) { return ctx.getType(name); } public static String[] getAliases(String name) { return ctx.getAliases(name); } }