Package overit.geocall.cdi
Class BeanFactory
java.lang.Object
overit.geocall.cdi.BeanFactory
Utility class used to resolve the CDI injection points
-
Method Summary
Modifier and TypeMethodDescription<T> TObtains a child instance of the given type and creates a new instance of the resolved bean, resolving the injection points.<T> TObtains a child instance of the given type and creates a new instance of the resolved bean, resolving the injection points.<T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> cls) Obtains a provider for the specified type allowing for lazy on-demand retrieval of instancesstatic BeanFactory<T> TCreate a new instance of the exacted passed bean's class, resolving the injection points.<T> Optional<T> selectJust(Class<T> cls) Selects a bean instance of the exact class type (not subclasses).voidsetContext(org.springframework.context.ApplicationContext context)
-
Method Details
-
getInstance
- Returns:
- the only instance of this class
-
setContext
@Autowired public void setContext(org.springframework.context.ApplicationContext context) -
get
Obtains a child instance of the given type and creates a new instance of the resolved bean, resolving the injection points.- Type Parameters:
T- the type of the returned instance- Parameters:
cls- the bean's class to instantiatequalifier- the bean's qualifier- Returns:
- the new class instance with the injection point resolved or null if
ApplicationContexthas not been initialized - Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException- if no bean of the given type was foundorg.springframework.beans.factory.NoUniqueBeanDefinitionException- if more than one bean of the given type was foundorg.springframework.beans.BeansException- if the bean could not be created
-
get
Obtains a child instance of the given type and creates a new instance of the resolved bean, resolving the injection points.- Type Parameters:
T- the type of the returned instance- Parameters:
cls- the bean's class to instantiate- Returns:
- the new class instance with the injection point resolved or null if
ApplicationContexthas not been initialized - Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException- if no bean of the given type was foundorg.springframework.beans.factory.NoUniqueBeanDefinitionException- if more than one bean of the given type was foundorg.springframework.beans.BeansException- if the bean could not be created
-
getBeanProvider
Obtains a provider for the specified type allowing for lazy on-demand retrieval of instances- Type Parameters:
T- the type of the returned instance- Parameters:
cls- the bean's class to instantiate- Returns:
- a corresponding provider handle or null if
ApplicationContexthas not been initialized
-
getJust
Create a new instance of the exacted passed bean's class, resolving the injection points.- Type Parameters:
T- the type of the returned instance- Parameters:
cls- the bean's class to instantiate- Returns:
- the new class instance with the injection point resolved
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException- if no bean of the given type was foundorg.springframework.beans.factory.NoUniqueBeanDefinitionException- if more than one bean of the given type was foundorg.springframework.beans.BeansException- if the bean could not be created
-
selectJust
Selects a bean instance of the exact class type (not subclasses). For singleton beans, instances are cached for performance. For prototype/request/session/company scoped beans, only metadata is cached.- Type Parameters:
T- the type of the returned instance- Parameters:
cls- the exact bean's class to find- Returns:
- an Optional containing the bean instance if found, empty otherwise
-