@Component public class SpringBuilder extends Object implements org.springframework.context.ApplicationContextAware
| Constructor and Description |
|---|
SpringBuilder() |
| Modifier and Type | Method and Description |
|---|---|
static String |
getActiveProfile()
获取当前的环境配置,当有多个环境配置时,只获取第一个
|
static String[] |
getActiveProfiles()
获取当前的环境配置,无配置返回null
|
static String |
getApplicationName()
获取应用程序名称
|
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 org.springframework.beans.factory.ListableBeanFactory |
getBeanFactory()
获取
ListableBeanFactory,可能为ConfigurableListableBeanFactory 或 ApplicationContextAware |
static String[] |
getBeanNamesForType(Class<?> type)
获取指定类型对应的Bean名称,包括子类
|
static <T> Map<String,T> |
getBeansOfType(Class<T> type)
获取指定类型对应的所有Bean,包括子类
|
static org.springframework.context.ConfigurableApplicationContext |
getContext() |
static String |
getProperty(String key)
获取配置文件配置项的值
|
static boolean |
isDemoMode()
当前是否开发/测试模式
|
static boolean |
isDevMode()
当前是否开发环境
|
static boolean |
isTestMode()
当前是否测试环境
|
static void |
refreshContext()
加载或刷新配置信息,可能来自基于java的配置、XML文件、属性文件、关系数据库模式或其他一些格式
|
static void |
registerBeanDefinition(Class clazz)
动态向Spring注册Bean
|
static void |
registerSingleton(Class clazz)
动态向Spring注册Bean
|
static void |
registerSingleton(Class clazz,
Object bean)
动态向Spring注册Bean
由
BeanFactory 实现,通过工具开放API |
static void |
removeContext()
删除context信息
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
static void |
setContext(org.springframework.context.ConfigurableApplicationContext context) |
static void |
unRegisterSingleton(String beanName)
注销bean
将Spring中的bean注销,请谨慎使用
|
public static org.springframework.context.ConfigurableApplicationContext getContext()
public static void setContext(org.springframework.context.ConfigurableApplicationContext context)
public static org.springframework.beans.factory.ListableBeanFactory getBeanFactory()
ListableBeanFactory,可能为ConfigurableListableBeanFactory 或 ApplicationContextAwareListableBeanFactorypublic 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 String getProperty(String key)
key - 配置项keypublic static String[] getActiveProfiles()
public static String getActiveProfile()
public static void registerBeanDefinition(Class clazz)
clazz - 类型public static void registerSingleton(Class clazz)
clazz - 类型public static void registerSingleton(Class clazz, Object bean)
BeanFactory 实现,通过工具开放APIclazz - 类型bean - 对象public static void unRegisterSingleton(String beanName)
beanName - bean名称public static void refreshContext()
public static void removeContext()
public static String getApplicationName()
public static boolean isDemoMode()
public static boolean isDevMode()
public static boolean isTestMode()
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext in interface org.springframework.context.ApplicationContextAwareCopyright © 2021. All rights reserved.