Enum Class BeanSource
- All Implemented Interfaces:
Serializable,Comparable<BeanSource>,Constable
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
BeanFactorySpringFactoriesLoaderServiceLoader
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionBean fromBean Factory.Bean fromJava Service Provider, the given type fromMETA-INF/servicesfiles.Bean fromSpring Factories, the given type from "META-INF/spring.factories" files. -
Method Summary
Modifier and TypeMethodDescriptiongetBeanTypes(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Class<T> beanType) Gets the set of bean types that are assignable to the givenbeanTypefrom this source.registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, BeanSource[] beanSources, Class<?>... beanTypes) Registers beans into theBeanDefinitionRegistryderived from the givenConfigurableListableBeanFactoryusing the specifiedBeanSources.registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Class<?>... beanTypes) Registers beans into theBeanDefinitionRegistryderived from the givenConfigurableListableBeanFactoryfrom this source.registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, BeanSource[] beanSources, Class<?>... beanTypes) Registers beans into the givenBeanDefinitionRegistryfrom the specifiedBeanSources.registerBeans(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<?>... beanTypes) Registers beans into the givenBeanDefinitionRegistryfrom this source.registerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, BeanSource[] beanSources, Class<?>... beanTypes) Registers beans into the givenBeanDefinitionRegistryfrom the specifiedBeanSources.registerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<?>... beanTypes) Registers beans into the givenBeanDefinitionRegistryfrom this source.static BeanSourceReturns the enum constant of this class with the specified name.static BeanSource[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
BEAN_FACTORY
Bean fromBean Factory.- See Also:
-
BeanFactoryConfigurableListableBeanFactory
-
SPRING_FACTORIES
Bean fromSpring Factories, the given type from "META-INF/spring.factories" files.- See Also:
-
SpringFactoriesLoader
-
JAVA_SERVICE_PROVIDER
Bean fromJava Service Provider, the given type fromMETA-INF/servicesfiles.- See Also:
-
-
Method Details
-
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
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 nameNullPointerException- 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 givenbeanTypefrom this source. -
registerBeans
@Nonnull @Immutable public Map<Class<?>,String> registerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<?>... beanTypes) Registers beans into the givenBeanDefinitionRegistryfrom this source.This method discovers bean classes for the specified
beanTypesusing thisBeanSource, and registers them as generic beans. The underlyingConfigurableListableBeanFactoryis 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- theBeanDefinitionRegistryto register beans intobeanTypes- the target bean types to search for and register- Returns:
- an unmodifiable
Mapwhere 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 theBeanDefinitionRegistryderived from the givenConfigurableListableBeanFactoryfrom this source.This method discovers bean classes for the specified
beanTypesusing thisBeanSource, and registers them as generic beans. The underlyingBeanDefinitionRegistryis derived from the providedConfigurableListableBeanFactory.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- theConfigurableListableBeanFactoryto use for resolution and to derive the registrybeanTypes- the target bean types to search for and register- Returns:
- an unmodifiable
Mapwhere 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 givenBeanDefinitionRegistryfrom this source.This method discovers bean classes for the specified
beanTypesusing thisBeanSource, 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- theConfigurableListableBeanFactoryto use for resolutionregistry- theBeanDefinitionRegistryto register beans intobeanTypes- the target bean types to search for and register- Returns:
- an unmodifiable
Mapwhere 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 theBeanDefinitionRegistryderived from the givenConfigurableListableBeanFactoryusing the specifiedBeanSources.This method iterates over the provided
beanSources, retrieves the bean classes for eachbeanTypefrom each source, and registers them as generic beans. If multiple sources provide beans for the same type, the behavior depends on the underlyingBeanDefinitionRegistryimplementation (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- theConfigurableListableBeanFactoryto use for resolution and to derive the registrybeanSources- the array ofBeanSources to use for discovering bean classesbeanTypes- the target bean types to search for and register- Returns:
- an unmodifiable
Mapwhere keys are the registered bean classes and values are their corresponding bean names - Throws:
IllegalArgumentException- ifbeanSourcesisnullor 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 givenBeanDefinitionRegistryfrom the specifiedBeanSources.This method iterates over the provided
beanSources, retrieves the bean classes for eachbeanTypefrom each source, and registers them as generic beans. If multiple sources provide beans for the same type, the behavior depends on the underlyingBeanDefinitionRegistryimplementation (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- theBeanDefinitionRegistryto register beans intobeanSources- the array ofBeanSources to use for discovering bean classesbeanTypes- the target bean types to search for and register- Returns:
- an unmodifiable
Mapwhere keys are the registered bean classes and values are their corresponding bean names - Throws:
IllegalArgumentException- ifbeanSourcesisnullor 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 givenBeanDefinitionRegistryfrom the specifiedBeanSources.This method iterates over the provided
beanSources, retrieves the bean classes for eachbeanTypefrom each source, and registers them as generic beans. If multiple sources provide beans for the same type, the behavior depends on the underlyingBeanDefinitionRegistryimplementation (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- theConfigurableListableBeanFactoryto use for resolution and bean class detectionregistry- theBeanDefinitionRegistryto register beans intobeanSources- the array ofBeanSources to use for discovering bean classesbeanTypes- the target bean types to search for and register- Returns:
- an unmodifiable
Mapwhere keys are the registered bean classes and values are their corresponding bean names - Throws:
IllegalArgumentException- ifbeanSourcesisnullor empty- See Also:
-