@Component public class ApplicationContextUtils extends Object implements org.springframework.context.ApplicationContextAware
| 限定符和类型 | 字段和说明 |
|---|---|
static org.springframework.context.ApplicationContext |
context
Spring应用上下文环境
|
| 构造器和说明 |
|---|
ApplicationContextUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
containsBean(String name)
如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
|
static String[] |
getActiveProfile()
获取当前环境
|
static String[] |
getAliases(String name)
如果给定的bean名字在bean定义中有别名,则返回这些别名
|
static <T> T |
getBean(Class<T> requiredType)
通过类型获取上下文中的bean
|
static Object |
getBean(String name)
通过名字获取上下文中的bean
|
static <T> T |
getBean(String name,
Class<T> requiredType)
获取类型为requiredType的对象 如果bean不能被类型转换,相应的异常将会被抛出(BeanNotOfRequiredTypeException)
|
static List<Object> |
getBeansWithAnnotation(Class<? extends Annotation> annotationType) |
static org.springframework.context.ApplicationContext |
getContext()
获取上下文
|
static String |
getProperty(String key)
获取指定配置的属性
|
static <T> T |
getProperty(String key,
Class<T> target)
获取指定配置的属性
|
static Class |
getType(String name) |
static boolean |
isSingleton(String name)
判断以给定名字注册的bean定义是一个singleton还是一个prototype。
|
static <T> T |
registerBean(String beanName,
Class<T> requiredType) |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
static void |
setContext(org.springframework.context.ApplicationContext context)
实现ApplicationContextAware接口的回调方法,设置上下文环境
|
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext 在接口中 org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic static org.springframework.context.ApplicationContext getContext()
public static void setContext(org.springframework.context.ApplicationContext context)
context - public static Object getBean(String name)
name - public static <T> T getBean(String name, Class<T> requiredType)
name - bean注册名requiredType - 返回对象类型public static <T> T getBean(Class<T> requiredType)
requiredType - public static boolean containsBean(String name)
name - public static boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
name - org.springframework.beans.factory.NoSuchBeanDefinitionExceptionpublic static Class getType(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
name - org.springframework.beans.factory.NoSuchBeanDefinitionExceptionpublic static String[] getAliases(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
name - org.springframework.beans.factory.NoSuchBeanDefinitionExceptionpublic static String[] getActiveProfile()
public static List<Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
Copyright © 2022 Pivotal Software, Inc.. All rights reserved.