public abstract class

AbstractBeanDefinitionReader

extends Object
implements BeanDefinitionReader EnvironmentCapable
java.lang.Object
   ↳ org.springframework.beans.factory.support.AbstractBeanDefinitionReader
Known Direct Subclasses

Class Overview

Abstract base class for bean definition readers which implement the BeanDefinitionReader interface.

Provides common properties like the bean factory to work on and the class loader to use for loading bean classes.

Summary

Fields
protected final Log logger Logger available to subclasses
Protected Constructors
AbstractBeanDefinitionReader(BeanDefinitionRegistry registry)
Create a new AbstractBeanDefinitionReader for the given bean factory.
Public Methods
ClassLoader getBeanClassLoader()
Return the class loader to use for bean classes.
final BeanDefinitionRegistry getBeanFactory()
BeanNameGenerator getBeanNameGenerator()
Return the BeanNameGenerator to use for anonymous beans (without explicit bean name specified).
Environment getEnvironment()
Return the Environment for this object
final BeanDefinitionRegistry getRegistry()
Return the bean factory to register the bean definitions with.
ResourceLoader getResourceLoader()
Return the resource loader to use for resource locations.
int loadBeanDefinitions(String location, Set<Resource> actualResources)
Load bean definitions from the specified resource location.
int loadBeanDefinitions(Resource... resources)
Load bean definitions from the specified resources.
int loadBeanDefinitions(String location)
Load bean definitions from the specified resource location.
int loadBeanDefinitions(String... locations)
Load bean definitions from the specified resource locations.
void setBeanClassLoader(ClassLoader beanClassLoader)
Set the ClassLoader to use for bean classes.
void setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
Set the BeanNameGenerator to use for anonymous beans (without explicit bean name specified).
void setEnvironment(Environment environment)
Set the Environment to use when reading bean definitions.
void setResourceLoader(ResourceLoader resourceLoader)
Set the ResourceLoader to use for resource locations.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.support.BeanDefinitionReader
From interface org.springframework.core.env.EnvironmentCapable

Fields

protected final Log logger

Also: SpringBeans

Logger available to subclasses

Protected Constructors

protected AbstractBeanDefinitionReader (BeanDefinitionRegistry registry)

Also: SpringBeans

Create a new AbstractBeanDefinitionReader for the given bean factory.

If the passed-in bean factory does not only implement the BeanDefinitionRegistry interface but also the ResourceLoader interface, it will be used as default ResourceLoader as well. This will usually be the case for ApplicationContext implementations.

If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a PathMatchingResourcePatternResolver.

If the the passed-in bean factory also implements EnvironmentCapable its environment will be used by this reader. Otherwise, the reader will initialize and use a DefaultEnvironment. All ApplicationContext implementations are EnvironmentCapable, while normal BeanFactory implementations are not.

Parameters
registry the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry

Public Methods

public ClassLoader getBeanClassLoader ()

Also: SpringBeans

Return the class loader to use for bean classes.

null suggests to not load bean classes eagerly but rather to just register bean definitions with class names, with the corresponding Classes to be resolved later (or never).

public final BeanDefinitionRegistry getBeanFactory ()

Also: SpringBeans

public BeanNameGenerator getBeanNameGenerator ()

Also: SpringBeans

Return the BeanNameGenerator to use for anonymous beans (without explicit bean name specified).

public Environment getEnvironment ()

Also: SpringBeans

Return the Environment for this object

public final BeanDefinitionRegistry getRegistry ()

Also: SpringBeans

Return the bean factory to register the bean definitions with.

The factory is exposed through the BeanDefinitionRegistry interface, encapsulating the methods that are relevant for bean definition handling.

public ResourceLoader getResourceLoader ()

Also: SpringBeans

Return the resource loader to use for resource locations. Can be checked for the ResourcePatternResolver interface and cast accordingly, for loading multiple resources for a given resource pattern.

Null suggests that absolute resource loading is not available for this bean definition reader.

This is mainly meant to be used for importing further resources from within a bean definition resource, for example via the "import" tag in XML bean definitions. It is recommended, however, to apply such imports relative to the defining resource; only explicit full resource locations will trigger absolute resource loading.

There is also a loadBeanDefinitions(String) method available, for loading bean definitions from a resource location (or location pattern). This is a convenience to avoid explicit ResourceLoader handling.

public int loadBeanDefinitions (String location, Set<Resource> actualResources)

Load bean definitions from the specified resource location.

The location can also be a location pattern, provided that the ResourceLoader of this bean definition reader is a ResourcePatternResolver.

Parameters
location the resource location, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader
actualResources a Set to be filled with the actual Resource objects that have been resolved during the loading process. May be null to indicate that the caller is not interested in those Resource objects.
Returns
  • the number of bean definitions found
Throws
BeanDefinitionStoreException in case of loading or parsing errors

public int loadBeanDefinitions (Resource... resources)

Load bean definitions from the specified resources.

Parameters
resources the resource descriptors
Returns
  • the number of bean definitions found

public int loadBeanDefinitions (String location)

Also: SpringBeans

Load bean definitions from the specified resource location.

The location can also be a location pattern, provided that the ResourceLoader of this bean definition reader is a ResourcePatternResolver.

Parameters
location the resource location, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader
Returns
  • the number of bean definitions found

public int loadBeanDefinitions (String... locations)

Load bean definitions from the specified resource locations.

Parameters
locations the resource locations, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader
Returns
  • the number of bean definitions found

public void setBeanClassLoader (ClassLoader beanClassLoader)

Also: SpringBeans

Set the ClassLoader to use for bean classes.

Default is null, which suggests to not load bean classes eagerly but rather to just register bean definitions with class names, with the corresponding Classes to be resolved later (or never).

public void setBeanNameGenerator (BeanNameGenerator beanNameGenerator)

Also: SpringBeans

Set the BeanNameGenerator to use for anonymous beans (without explicit bean name specified).

Default is a DefaultBeanNameGenerator.

public void setEnvironment (Environment environment)

Set the Environment to use when reading bean definitions. Most often used for evaluating profile information to determine which bean definitions should be read and which should be omitted.

public void setResourceLoader (ResourceLoader resourceLoader)

Set the ResourceLoader to use for resource locations. If specifying a ResourcePatternResolver, the bean definition reader will be capable of resolving resource patterns to Resource arrays.

Default is PathMatchingResourcePatternResolver, also capable of resource pattern resolving through the ResourcePatternResolver interface.

Setting this to null suggests that absolute resource loading is not available for this bean definition reader.