Class BeanFactory

java.lang.Object
overit.geocall.cdi.BeanFactory

public class BeanFactory extends Object
Utility class used to resolve the CDI injection points
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    get(Class<T> cls)
    Obtains a child instance of the given type and creates a new instance of the resolved bean, resolving the injection points.
    <T> T
    get(Class<T> cls, String qualifier)
    Obtains 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>
    Obtains a provider for the specified type allowing for lazy on-demand retrieval of instances
     
    <T> T
    getJust(Class<T> cls)
    Create 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).
    void
    setContext(org.springframework.context.ApplicationContext context)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      public static BeanFactory getInstance()
      Returns:
      the only instance of this class
    • setContext

      @Autowired public void setContext(org.springframework.context.ApplicationContext context)
    • get

      public <T> T get(Class<T> cls, String qualifier)
      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
      qualifier - the bean's qualifier
      Returns:
      the new class instance with the injection point resolved or null if ApplicationContext has not been initialized
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException - if no bean of the given type was found
      org.springframework.beans.factory.NoUniqueBeanDefinitionException - if more than one bean of the given type was found
      org.springframework.beans.BeansException - if the bean could not be created
    • get

      public <T> T get(Class<T> cls)
      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 ApplicationContext has not been initialized
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException - if no bean of the given type was found
      org.springframework.beans.factory.NoUniqueBeanDefinitionException - if more than one bean of the given type was found
      org.springframework.beans.BeansException - if the bean could not be created
    • getBeanProvider

      public <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 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 ApplicationContext has not been initialized
    • getJust

      public <T> T getJust(Class<T> cls)
      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 found
      org.springframework.beans.factory.NoUniqueBeanDefinitionException - if more than one bean of the given type was found
      org.springframework.beans.BeansException - if the bean could not be created
    • selectJust

      public <T> Optional<T> selectJust(Class<T> cls)
      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