@Component public class SpringAware extends Object implements org.springframework.context.ApplicationContextAware
1. Spring IOC容器中的bean对象获取 2. ApplicaitonContext 对象获取
| Constructor and Description |
|---|
SpringAware() |
| Modifier and Type | Method and Description |
|---|---|
static String |
getActiveProfile()
获取当前的环境配置,当有多个环境配置时,只获取第一个
|
static String[] |
getActiveProfiles()
获取当前的环境配置,无配置返回null
|
static org.springframework.context.ApplicationContext |
getApplicationContext()
获取applicationContext
|
static <T> T |
getBean(Class<T> clazz)
通过class获取Bean
|
static <T> T |
getBean(String name)
通过name获取 Bean
|
static <T> T |
getBean(String name,
Class<T> clazz)
通过name,以及Clazz返回指定的Bean
|
static <T> T |
getBean(org.aoju.bus.core.lang.Types<T> reference)
通过类型参考返回带泛型参数的Bean
|
static String[] |
getBeanNamesForType(Class<?> type)
获取指定类型对应的Bean名称,包括子类
|
static <T> Map<String,T> |
getBeansOfType(Class<T> type)
获取指定类型对应的所有Bean,包括子类
|
static Map<String,Object> |
getBeanWithAnnotation(Class<? extends Annotation> annType)
获取指定注解的Bean
|
static String |
getProperty(String key)
获取配置文件配置项的值
|
static boolean |
isDemoMode()
当前是否开发/测试模式
|
static boolean |
isDevMode()
当前是否开发环境
|
static boolean |
isTestMode()
当前是否测试环境
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
public static org.springframework.context.ApplicationContext getApplicationContext()
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext in interface org.springframework.context.ApplicationContextAwarepublic static <T> T getBean(String name)
T - Bean类型name - Bean名称public static <T> T getBean(Class<T> clazz)
T - Bean类型clazz - Bean类public static <T> T getBean(String name, Class<T> clazz)
T - bean类型name - Bean名称clazz - bean类型public static <T> T getBean(org.aoju.bus.core.lang.Types<T> reference)
T - Bean类型reference - 类型参考,用于持有转换后的泛型类型public static <T> Map<String,T> getBeansOfType(Class<T> type)
T - Bean类型type - 类、接口,null表示获取所有beanpublic static String[] getBeanNamesForType(Class<?> type)
type - 类、接口,null表示获取所有bean名称public static Map<String,Object> getBeanWithAnnotation(Class<? extends Annotation> annType)
annType - 指定注解类型public static String getProperty(String key)
key - 配置项 keypublic static String[] getActiveProfiles()
public static String getActiveProfile()
public static boolean isDemoMode()
public static boolean isDevMode()
public static boolean isTestMode()
Copyright © 2021. All rights reserved.