@Component public class ApplicationContextUtils extends Object implements org.springframework.context.ApplicationContextAware
Constructor and Description |
---|
ApplicationContextUtils() |
Modifier and Type | Method and Description |
---|---|
static org.springframework.context.ApplicationContext |
getApplicationContext()
|
static <T> T |
getBean(Class<T> clazz)
获取Spring容器中的Bean - 通过Bean类型
|
static Object |
getBean(String name)
获取Spring容器中的Bean - 通过Bean名称
|
static <T> T |
getBean(String name,
Class<T> clazz)
获取Spring容器中的Bean - 通过Bean名称与Bean类型精准获取
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public static org.springframework.context.ApplicationContext getApplicationContext()
public static Object getBean(String name)
name
- Bean名称public static <T> T getBean(Class<T> clazz)
T
- Bean类型clazz
- 泛型类型,可以是接口或超类Copyright © 2022 Pivotal Software, Inc.. All rights reserved.