Class BeanDefinitionReaderUtils
java.lang.Object
org.springframework.beans.factory.support.BeanDefinitionReaderUtils
Utility methods that are useful for bean definition reader implementations.
Mainly intended for internal use.
- Since:
- 1.1
- Author:
- Juergen Hoeller, Rob Harrop
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractBeanDefinition
createBeanDefinition
(String parentName, String className, ClassLoader classLoader) Create a new GenericBeanDefinition for the given parent name and class name, eagerly loading the bean class if a ClassLoader has been specified.static String
generateBeanName
(BeanDefinition beanDefinition, BeanDefinitionRegistry registry) Generate a bean name for the given top-level bean definition, unique within the given bean factory.static String
generateBeanName
(BeanDefinition definition, BeanDefinitionRegistry registry, boolean isInnerBean) Generate a bean name for the given bean definition, unique within the given bean factory.static void
registerBeanDefinition
(BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry) Register the given bean definition with the given bean factory.static String
registerWithGeneratedName
(AbstractBeanDefinition definition, BeanDefinitionRegistry registry) Register the given bean definition with a generated name, unique within the given bean factory.static String
uniqueBeanName
(String beanName, BeanDefinitionRegistry registry) Turn the given bean name into a unique bean name for the given bean factory, appending a unique counter as suffix if necessary.
-
Field Details
-
GENERATED_BEAN_NAME_SEPARATOR
Separator for generated bean names. If a class name or parent name is not unique, "#1", "#2" etc will be appended, until the name becomes unique.- See Also:
-
-
Constructor Details
-
BeanDefinitionReaderUtils
public BeanDefinitionReaderUtils()
-
-
Method Details
-
createBeanDefinition
public static AbstractBeanDefinition createBeanDefinition(@Nullable String parentName, @Nullable String className, @Nullable ClassLoader classLoader) throws ClassNotFoundException Create a new GenericBeanDefinition for the given parent name and class name, eagerly loading the bean class if a ClassLoader has been specified.- Parameters:
parentName
- the name of the parent bean, if anyclassName
- the name of the bean class, if anyclassLoader
- the ClassLoader to use for loading bean classes (can benull
to just register bean classes by name)- Returns:
- the bean definition
- Throws:
ClassNotFoundException
- if the bean class could not be loaded
-
generateBeanName
public static String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry registry) throws BeanDefinitionStoreException Generate a bean name for the given top-level bean definition, unique within the given bean factory.- Parameters:
beanDefinition
- the bean definition to generate a bean name forregistry
- the bean factory that the definition is going to be registered with (to check for existing bean names)- Returns:
- the generated bean name
- Throws:
BeanDefinitionStoreException
- if no unique name can be generated for the given bean definition- See Also:
-
generateBeanName
public static String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry, boolean isInnerBean) throws BeanDefinitionStoreException Generate a bean name for the given bean definition, unique within the given bean factory.- Parameters:
definition
- the bean definition to generate a bean name forregistry
- the bean factory that the definition is going to be registered with (to check for existing bean names)isInnerBean
- whether the given bean definition will be registered as inner bean or as top-level bean (allowing for special name generation for inner beans versus top-level beans)- Returns:
- the generated bean name
- Throws:
BeanDefinitionStoreException
- if no unique name can be generated for the given bean definition
-
uniqueBeanName
Turn the given bean name into a unique bean name for the given bean factory, appending a unique counter as suffix if necessary.- Parameters:
beanName
- the original bean nameregistry
- the bean factory that the definition is going to be registered with (to check for existing bean names)- Returns:
- the unique bean name to use
- Since:
- 5.1
-
registerBeanDefinition
public static void registerBeanDefinition(BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry) throws BeanDefinitionStoreException Register the given bean definition with the given bean factory.- Parameters:
definitionHolder
- the bean definition including name and aliasesregistry
- the bean factory to register with- Throws:
BeanDefinitionStoreException
- if registration failed
-
registerWithGeneratedName
public static String registerWithGeneratedName(AbstractBeanDefinition definition, BeanDefinitionRegistry registry) throws BeanDefinitionStoreException Register the given bean definition with a generated name, unique within the given bean factory.- Parameters:
definition
- the bean definition to generate a bean name forregistry
- the bean factory to register with- Returns:
- the generated bean name
- Throws:
BeanDefinitionStoreException
- if no unique name can be generated for the given bean definition or the definition cannot be registered
-