Package com.luna.common.spring
Class SpringBeanService
java.lang.Object
com.luna.common.spring.SpringBeanService
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
@Component
public class SpringBeanService
extends Object
implements org.springframework.context.ApplicationContextAware
Spring的bean加载服务类
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static org.springframework.context.ApplicationContextspring bean上下文 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectgetBeanByName(String name) 获取bean实例static <T> TgetBeanByName(String name, Class<T> clazz) 获取bean实例getBeansOfType(Class<T> clazz) 获取此类型所有的beanstatic <T> TgetSingleBeanByType(Class<T> clazz) 根据class 类型获取beanvoidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)
-
Field Details
-
applicationContext
protected static org.springframework.context.ApplicationContext applicationContextspring bean上下文
-
-
Constructor Details
-
SpringBeanService
public SpringBeanService()
-
-
Method Details
-
getBeanByName
public static <T> T getBeanByName(String name, Class<T> clazz) throws org.springframework.beans.BeansException 获取bean实例- Throws:
org.springframework.beans.BeansException
-
getBeanByName
获取bean实例- Throws:
org.springframework.beans.BeansException
-
getBeansOfType
获取此类型所有的bean- Parameters:
clazz-- Returns:
- Throws:
org.springframework.beans.BeansException
-
getSingleBeanByType
根据class 类型获取bean- Parameters:
clazz-- Returns:
- Throws:
org.springframework.beans.BeansException- 当有继承或者接口时(多个实现类)getBean(clazz)会报错 所以通过class name比较来获取唯一那个beanException
-
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
-