Enum Class BeanSource

java.lang.Object
java.lang.Enum<BeanSource>
io.microsphere.spring.beans.BeanSource
All Implemented Interfaces:
Serializable, Comparable<BeanSource>, Constable

public enum BeanSource extends Enum<BeanSource>
The enumeration of Bean Sources
Since:
1.0.0
Author:
Mercy
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Bean from Bean Factory.
    Bean from Java Service Provider, the given type from META-INF/services files.
    Bean from Spring Factories, the given type from "META-INF/spring.factories" files.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract <T> Set<Class<T>>
    getBeanTypes(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Class<T> beanType)
    Gets the set of bean types that are assignable to the given beanType from this source.
    static Map<Class<?>,String>
    registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, BeanSource[] beanSources, Class<?>... beanTypes)
    Registers beans into the BeanDefinitionRegistry derived from the given ConfigurableListableBeanFactory using the specified BeanSources.
    registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Class<?>... beanTypes)
    Registers beans into the BeanDefinitionRegistry derived from the given ConfigurableListableBeanFactory from this source.
    static Map<Class<?>,String>
    registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, BeanSource[] beanSources, Class<?>... beanTypes)
    Registers beans into the given BeanDefinitionRegistry from the specified BeanSources.
    registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<?>... beanTypes)
    Registers beans into the given BeanDefinitionRegistry from this source.
    static Map<Class<?>,String>
    registerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, BeanSource[] beanSources, Class<?>... beanTypes)
    Registers beans into the given BeanDefinitionRegistry from the specified BeanSources.
    registerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<?>... beanTypes)
    Registers beans into the given BeanDefinitionRegistry from this source.
    static BeanSource
    Returns the enum constant of this class with the specified name.
    static BeanSource[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • BEAN_FACTORY

      public static final BeanSource BEAN_FACTORY
      Bean from Bean Factory.
      See Also:
      • BeanFactory
      • ConfigurableListableBeanFactory
    • SPRING_FACTORIES

      public static final BeanSource SPRING_FACTORIES
      Bean from Spring Factories, the given type from "META-INF/spring.factories" files.
      See Also:
      • SpringFactoriesLoader
    • JAVA_SERVICE_PROVIDER

      public static final BeanSource JAVA_SERVICE_PROVIDER
      Bean from Java Service Provider, the given type from META-INF/services files.
      See Also:
  • Method Details

    • values

      public static BeanSource[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static BeanSource valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getBeanTypes

      @Nonnull @Immutable public abstract <T> Set<Class<T>> getBeanTypes(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Class<T> beanType)
      Gets the set of bean types that are assignable to the given beanType from this source.
      Type Parameters:
      T - the type of the bean
      Parameters:
      beanFactory - the ConfigurableListableBeanFactory to use for resolution
      beanType - the target bean type to search for
      Returns:
      a Set of Class objects representing the bean types found, never null
    • registerBeans

      @Nonnull @Immutable public Map<Class<?>,String> registerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<?>... beanTypes)
      Registers beans into the given BeanDefinitionRegistry from this source.

      This method discovers bean classes for the specified beanTypes using this BeanSource, and registers them as generic beans. The underlying ConfigurableListableBeanFactory is derived from the provided registry for type resolution if necessary.

      Example Usage:

      
       // Register beans from Spring Factories source
       BeanDefinitionRegistry registry = ...;
      
       Map<Class<?>, String> registeredBeans = BeanSource.SPRING_FACTORIES.registerBeans(
           registry,
           MyService.class,
           AnotherService.class
       );
      
       // The map contains the registered bean classes as keys and their bean names as values
       registeredBeans.forEach((beanClass, beanName) -> {
           System.out.println("Registered: " + beanClass.getName() + " with name: " + beanName);
       });
       
      Parameters:
      registry - the BeanDefinitionRegistry to register beans into
      beanTypes - the target bean types to search for and register
      Returns:
      an unmodifiable Map where keys are the registered bean classes and values are their corresponding bean names
      See Also:
    • registerBeans

      @Nonnull @Immutable public Map<Class<?>,String> registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Class<?>... beanTypes)
      Registers beans into the BeanDefinitionRegistry derived from the given ConfigurableListableBeanFactory from this source.

      This method discovers bean classes for the specified beanTypes using this BeanSource, and registers them as generic beans. The underlying BeanDefinitionRegistry is derived from the provided ConfigurableListableBeanFactory.

      Example Usage:

      
       // Register beans from Spring Factories source
       ConfigurableListableBeanFactory beanFactory = ...;
      
       Map<Class<?>, String> registeredBeans = BeanSource.SPRING_FACTORIES.registerBeans(
           beanFactory,
           MyService.class,
           AnotherService.class
       );
      
       // The map contains the registered bean classes as keys and their bean names as values
       registeredBeans.forEach((beanClass, beanName) -> {
           System.out.println("Registered: " + beanClass.getName() + " with name: " + beanName);
       });
       
      Parameters:
      beanFactory - the ConfigurableListableBeanFactory to use for resolution and to derive the registry
      beanTypes - the target bean types to search for and register
      Returns:
      an unmodifiable Map where keys are the registered bean classes and values are their corresponding bean names
      See Also:
    • registerBeans

      @Nonnull @Immutable public Map<Class<?>,String> registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<?>... beanTypes)
      Registers beans into the given BeanDefinitionRegistry from this source.

      This method discovers bean classes for the specified beanTypes using this BeanSource, and registers them as generic beans.

      Example Usage:

      
       // Register beans from Spring Factories source
       ConfigurableListableBeanFactory beanFactory = ...;
       BeanDefinitionRegistry registry = ...;
      
       Map<Class<?>, String> registeredBeans = BeanSource.SPRING_FACTORIES.registerBeans(
           beanFactory,
           registry,
           MyService.class,
           AnotherService.class
       );
      
       // The map contains the registered bean classes as keys and their bean names as values
       registeredBeans.forEach((beanClass, beanName) -> {
           System.out.println("Registered: " + beanClass.getName() + " with name: " + beanName);
       });
       
      Parameters:
      beanFactory - the ConfigurableListableBeanFactory to use for resolution
      registry - the BeanDefinitionRegistry to register beans into
      beanTypes - the target bean types to search for and register
      Returns:
      an unmodifiable Map where keys are the registered bean classes and values are their corresponding bean names
      See Also:
    • registerBeans

      @Nonnull @Immutable public static Map<Class<?>,String> registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, BeanSource[] beanSources, Class<?>... beanTypes)
      Registers beans into the BeanDefinitionRegistry derived from the given ConfigurableListableBeanFactory using the specified BeanSources.

      This method iterates over the provided beanSources, retrieves the bean classes for each beanType from each source, and registers them as generic beans. If multiple sources provide beans for the same type, the behavior depends on the underlying BeanDefinitionRegistry implementation (typically, later registrations may override earlier ones if the bean name conflicts).

      Example Usage:

      
       // Register beans from Spring Factories and Java Service Provider sources
       ConfigurableListableBeanFactory beanFactory = ...;
      
       Map<Class<?>, String> registeredBeans = BeanSource.registerBeans(
           beanFactory,
           new BeanSource[]{BeanSource.SPRING_FACTORIES, BeanSource.JAVA_SERVICE_PROVIDER},
           MyService.class,
           AnotherService.class
       );
      
       // The map contains the registered bean classes as keys and their bean names as values
       registeredBeans.forEach((beanClass, beanName) -> {
           System.out.println("Registered: " + beanClass.getName() + " with name: " + beanName);
       });
       
      Parameters:
      beanFactory - the ConfigurableListableBeanFactory to use for resolution and to derive the registry
      beanSources - the array of BeanSources to use for discovering bean classes
      beanTypes - the target bean types to search for and register
      Returns:
      an unmodifiable Map where keys are the registered bean classes and values are their corresponding bean names
      Throws:
      IllegalArgumentException - if beanSources is null or empty
      See Also:
    • registerBeans

      @Nonnull @Immutable public static Map<Class<?>,String> registerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, BeanSource[] beanSources, Class<?>... beanTypes)
      Registers beans into the given BeanDefinitionRegistry from the specified BeanSources.

      This method iterates over the provided beanSources, retrieves the bean classes for each beanType from each source, and registers them as generic beans. If multiple sources provide beans for the same type, the behavior depends on the underlying BeanDefinitionRegistry implementation (typically, later registrations may override earlier ones if the bean name conflicts).

      Example Usage:

      
       // Register beans from Spring Factories and Java Service Provider sources
       BeanDefinitionRegistry registry = ...;
      
       Map<Class<?>, String> registeredBeans = BeanSource.registerBeans(
           registry,
           new BeanSource[]{BeanSource.SPRING_FACTORIES, BeanSource.JAVA_SERVICE_PROVIDER},
           MyService.class,
           AnotherService.class
       );
      
       // The map contains the registered bean classes as keys and their bean names as values
       registeredBeans.forEach((beanClass, beanName) -> {
           System.out.println("Registered: " + beanClass.getName() + " with name: " + beanName);
       });
       
      Parameters:
      registry - the BeanDefinitionRegistry to register beans into
      beanSources - the array of BeanSources to use for discovering bean classes
      beanTypes - the target bean types to search for and register
      Returns:
      an unmodifiable Map where keys are the registered bean classes and values are their corresponding bean names
      Throws:
      IllegalArgumentException - if beanSources is null or empty
      See Also:
    • registerBeans

      public static Map<Class<?>,String> registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, BeanSource[] beanSources, Class<?>... beanTypes)
      Registers beans into the given BeanDefinitionRegistry from the specified BeanSources.

      This method iterates over the provided beanSources, retrieves the bean classes for each beanType from each source, and registers them as generic beans. If multiple sources provide beans for the same type, the behavior depends on the underlying BeanDefinitionRegistry implementation (typically, later registrations may override earlier ones if the bean name conflicts).

      Example Usage:

      
       // Register beans from Spring Factories and Java Service Provider sources
       ConfigurableListableBeanFactory beanFactory = ...;
       BeanDefinitionRegistry registry = ...;
      
       Map<Class<?>, String> registeredBeans = BeanSource.registerBeans(
           beanFactory,
           registry,
           new BeanSource[]{BeanSource.SPRING_FACTORIES, BeanSource.JAVA_SERVICE_PROVIDER},
           MyService.class,
           AnotherService.class
       );
      
       // The map contains the registered bean classes as keys and their bean names as values
       registeredBeans.forEach((beanClass, beanName) -> {
           System.out.println("Registered: " + beanClass.getName() + " with name: " + beanName);
       });
       
      Parameters:
      beanFactory - the ConfigurableListableBeanFactory to use for resolution and bean class detection
      registry - the BeanDefinitionRegistry to register beans into
      beanSources - the array of BeanSources to use for discovering bean classes
      beanTypes - the target bean types to search for and register
      Returns:
      an unmodifiable Map where keys are the registered bean classes and values are their corresponding bean names
      Throws:
      IllegalArgumentException - if beanSources is null or empty
      See Also: