Class SpringUtils
java.lang.Object
com.codeupsoft.base.service.utils.SpringUtils
- All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
public class SpringUtils
extends Object
implements org.springframework.context.ApplicationContextAware
Spring工具类,用于获取和注册Bean.
- Author:
- Liu,Dongdong
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsBean(String name) 判断是否包含指定名称的Bean.static <T> T根据Bean类型获取Bean实例.static <T> T根据Bean名称获取Bean实例.static <T> T根据Bean名称和类型获取Bean实例.static booleanisSingleton(String name) 判断指定名称的Bean是否为单例.static voidregisterBean(String beanName, Object beanInstance) 动态注册Bean到Spring容器中.static voidremoveBean(String beanName) 从Spring容器中移除指定名称的Bean.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)
-
Constructor Details
-
SpringUtils
public SpringUtils()
-
-
Method Details
-
getBean
根据Bean名称获取Bean实例.- Parameters:
name- Bean名称- Returns:
- Bean实例
-
getBean
根据Bean类型获取Bean实例.- Parameters:
clazz- Bean类型- Returns:
- Bean实例
-
getBean
-
containsBean
判断是否包含指定名称的Bean.- Parameters:
name- Bean名称- Returns:
- 是否包含
-
isSingleton
判断指定名称的Bean是否为单例.- Parameters:
name- Bean名称- Returns:
- 是否为单例
-
registerBean
-
removeBean
从Spring容器中移除指定名称的Bean.- Parameters:
beanName- Bean的名称
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-