@Component public class SpringContextHelperUtil extends Object implements org.springframework.context.ApplicationContextAware
Constructor and Description |
---|
SpringContextHelperUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsBean(String name)
如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
|
static String[] |
getAliases(String name)
如果给定的bean名字在bean定义中有别名,则返回这些别名
|
static org.springframework.context.ApplicationContext |
getApplicationContext() |
static <T> T |
getBean(Class<T> clazz) |
static Object |
getBean(String name)
获取对象
|
static Object |
getBean(String name,
Class requiredType)
获取类型为requiredType的对象
如果bean不能被类型转换,相应的异常将会被抛出(BeanNotOfRequiredTypeException)
|
static <T> T |
getBeans(String name) |
static Class |
getType(String name) |
static boolean |
isSingleton(String name)
判断以给定名字注册的bean定义是一个singleton还是一个prototype。
如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
实现ApplicationContextAware接口的context注入函数, 将其存入静态变量
|
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
public static org.springframework.context.ApplicationContext getApplicationContext()
public static <T> T getBeans(String name)
name
- public static <T> T getBean(Class<T> clazz)
clazz
- public static Object getBean(String name) throws org.springframework.beans.BeansException
name
- org.springframework.beans.BeansException
public static Object getBean(String name, Class requiredType) throws org.springframework.beans.BeansException
name
- bean注册名requiredType
- 返回对象类型org.springframework.beans.BeansException
public static boolean containsBean(String name)
name
- public static boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
name
- org.springframework.beans.factory.NoSuchBeanDefinitionException
public static Class getType(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
name
- org.springframework.beans.factory.NoSuchBeanDefinitionException
Copyright © 2019. All rights reserved.