SpringUtils
@Component
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext context;
@Override
public void setApplicationContext(@Nullable ApplicationContext applicationContext) throws BeansException {
SpringUtils.context = (SpringUtils.context == null) ? applicationContext : SpringUtils.context;
}
public static ApplicationContext getContext() {
return context;
}
@SuppressWarnings("unchecked")
public static <T> T getBean(String name)
throws BeansException {
return (T) context.getBean(name);
}
public static <T> T getBean(Class<T> requiredType)
throws BeansException {
return context.getBean(requiredType);
}
public static <T> T getBean(String name, Class<T> requiredType)
throws BeansException {
return context.getBean(name, requiredType);
}
public static boolean containsBean(String name) {
return context.containsBean(name);
}
public static boolean isSingleton(String name)
throws NoSuchBeanDefinitionException {
return context.isSingleton(name);
}
public static Class getType(String name)
throws NoSuchBeanDefinitionException {
return context.getType(name);
}
public static String[] getAliases(String name)
throws NoSuchBeanDefinitionException {
return context.getAliases(name);
}
public static <T