完善SpringContextUtil工具类

This commit is contained in:
shuzheng 2017-01-07 19:58:22 +08:00
parent df46c84ccd
commit 0434b9ec33
1 changed files with 35 additions and 0 deletions

View File

@ -40,6 +40,14 @@ public class SpringContextUtil implements ApplicationContextAware {
return context.getBean(beanName);
}
/**
* 根据bean名称获取指定类型bean
* @param beanName bean名称
* @param clazz 返回的bean类型,若类型不匹配,将抛出异常
*/
public static <T> T getBean(String beanName, Class<T> clazz) {
return context.getBean(beanName, clazz);
}
/**
* 根据类型获取bean
* @param clazz
@ -54,4 +62,31 @@ public class SpringContextUtil implements ApplicationContextAware {
return t;
}
/**
* 是否包含bean
* @param beanName
* @return
*/
public static boolean containsBean(String beanName) {
return context.containsBean(beanName);
}
/**
* 是否是单例
* @param beanName
* @return
*/
public static boolean isSingleton(String beanName) {
return context.isSingleton(beanName);
}
/**
* bean的类型
* @param beanName
* @return
*/
public static Class getType(String beanName) {
return context.getType(beanName);
}
}