Top Description Fields Constructors Methods
org.springframework.beans.factory.support

public abstract Class AbstractBeanDefinitionReader

extends Object
implements BeanDefinitionReader, EnvironmentCapable
Class Inheritance
All Implemented Interfaces
org.springframework.core.env.EnvironmentCapable, org.springframework.beans.factory.support.BeanDefinitionReader
Known Direct Subclasses
org.springframework.beans.factory.support.PropertiesBeanDefinitionReader, org.springframework.beans.factory.xml.XmlBeanDefinitionReader, org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader
Imports
java.io.IOException, java.util.Collections, .Set, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.BeanDefinitionStoreException, org.springframework.core.env.Environment, .EnvironmentCapable, .StandardEnvironment, org.springframework.core.io.Resource, .ResourceLoader, org.springframework.core.io.support.PathMatchingResourcePatternResolver, .ResourcePatternResolver, org.springframework.lang.Nullable, org.springframework.util.Assert

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.

Authors
Juergen Hoeller, Chris Beams
Since
11.12.2003
See Also
BeanDefinitionReaderUtils

Field Summary

Modifier and TypeField and Description
private ClassLoader
private BeanNameGenerator
private Environment
protected final Log
logger

Logger available to subclasses.

private final BeanDefinitionRegistry
private ResourceLoader

Constructor Summary

AccessConstructor and Description
protected
AbstractBeanDefinitionReader(BeanDefinitionRegistry
the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
registry
)

Create a new AbstractBeanDefinitionReader for the given bean factory.

Method Summary

Modifier and TypeMethod and Description
public ClassLoader
public BeanNameGenerator
getBeanNameGenerator()

Implements org.springframework.beans.factory.support.BeanDefinitionReader.getBeanNameGenerator.

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

public Environment
getEnvironment()

Implements org.springframework.core.env.EnvironmentCapable.getEnvironment.

Return the Environment associated with this component.

public final BeanDefinitionRegistry
getRegistry()

Implements org.springframework.beans.factory.support.BeanDefinitionReader.getRegistry.

Return the bean factory to register the bean definitions with.

public ResourceLoader
public int
loadBeanDefinitions(Resource...
the resource descriptors
resources
)

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Load bean definitions from the specified resources.

public int
loadBeanDefinitions(String
the resource location, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader
location
)

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Load bean definitions from the specified resource location.

public int

Returns:

the number of bean definitions found
loadBeanDefinitions
(String
the resource location, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader
location
,
Set<Resource>
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.
actualResources
)

Load bean definitions from the specified resource location.

public int
loadBeanDefinitions(String...
the resource locations, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader
locations
)

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Load bean definitions from the specified resource locations.

public void
setBeanClassLoader(ClassLoader beanClassLoader)

Set the ClassLoader to use for bean classes.

public void
setBeanNameGenerator(BeanNameGenerator beanNameGenerator)

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

public void
setEnvironment(Environment environment)

Set the Environment to use when reading bean definitions.

public void
setResourceLoader(ResourceLoader resourceLoader)

Set the ResourceLoader to use for resource locations.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanClassLoaderback to summary
private ClassLoader beanClassLoader
Annotations
@Nullable
beanNameGeneratorback to summary
private BeanNameGenerator beanNameGenerator
environmentback to summary
private Environment environment
loggerback to summary
protected final Log logger

Logger available to subclasses.

registryback to summary
private final BeanDefinitionRegistry registry
resourceLoaderback to summary
private ResourceLoader resourceLoader
Annotations
@Nullable

Constructor Detail

AbstractBeanDefinitionReaderback to summary
protected AbstractBeanDefinitionReader(BeanDefinitionRegistry registry)

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 org.springframework.context.ApplicationContext implementations.

If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a org.springframework.core.io.support.PathMatchingResourcePatternResolver.

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

Parameters
registry:BeanDefinitionRegistry

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

See Also
setResourceLoader, setEnvironment

Method Detail

getBeanClassLoaderback to summary
public ClassLoader getBeanClassLoader()

Implements org.springframework.beans.factory.support.BeanDefinitionReader.getBeanClassLoader.

Doc from org.springframework.beans.factory.support.BeanDefinitionReader.getBeanClassLoader.

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).

Annotations
@Override
@Nullable
getBeanNameGeneratorback to summary
public BeanNameGenerator getBeanNameGenerator()

Implements org.springframework.beans.factory.support.BeanDefinitionReader.getBeanNameGenerator.

Doc from org.springframework.beans.factory.support.BeanDefinitionReader.getBeanNameGenerator.

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

Annotations
@Override
getEnvironmentback to summary
public Environment getEnvironment()

Implements org.springframework.core.env.EnvironmentCapable.getEnvironment.

Doc from org.springframework.core.env.EnvironmentCapable.getEnvironment.

Return the Environment associated with this component.

Annotations
@Override
getRegistryback to summary
public final BeanDefinitionRegistry getRegistry()

Implements org.springframework.beans.factory.support.BeanDefinitionReader.getRegistry.

Doc from org.springframework.beans.factory.support.BeanDefinitionReader.getRegistry.

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.

Annotations
@Override
getResourceLoaderback to summary
public ResourceLoader getResourceLoader()

Implements org.springframework.beans.factory.support.BeanDefinitionReader.getResourceLoader.

Doc from org.springframework.beans.factory.support.BeanDefinitionReader.getResourceLoader.

Return the ResourceLoader to use for resource locations.

Can be checked for the ResourcePatternResolver interface and cast accordingly, for loading multiple resources for a given resource pattern.

A null return value 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 path based 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.

Annotations
@Override
@Nullable
loadBeanDefinitionsback to summary
public int loadBeanDefinitions(Resource... resources) throws BeanDefinitionStoreException

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Doc from org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Load bean definitions from the specified resources.

Parameters
resources:Resource[]

the resource descriptors

Returns:int

the number of bean definitions found

Annotations
@Override
Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
loadBeanDefinitionsback to summary
public int loadBeanDefinitions(String location) throws BeanDefinitionStoreException

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Doc from org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

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:String

the resource location, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader

Returns:int

the number of bean definitions found

Annotations
@Override
Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
loadBeanDefinitionsback to summary
public int loadBeanDefinitions(String location, Set<Resource> actualResources) throws BeanDefinitionStoreException

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:String

the resource location, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader

actualResources:Set<Resource>

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:int

the number of bean definitions found

Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
See Also
getResourceLoader(), loadBeanDefinitions(org.springframework.core.io.Resource), loadBeanDefinitions(org.springframework.core.io.Resource[])
loadBeanDefinitionsback to summary
public int loadBeanDefinitions(String... locations) throws BeanDefinitionStoreException

Implements org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Doc from org.springframework.beans.factory.support.BeanDefinitionReader.loadBeanDefinitions.

Load bean definitions from the specified resource locations.

Parameters
locations:String[]

the resource locations, to be loaded with the ResourceLoader (or ResourcePatternResolver) of this bean definition reader

Returns:int

the number of bean definitions found

Annotations
@Override
Exceptions
BeanDefinitionStoreException:
in case of loading or parsing errors
setBeanClassLoaderback to summary
public void setBeanClassLoader(ClassLoader beanClassLoader)

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).

See Also
Thread#getContextClassLoader()
setBeanNameGeneratorback to summary
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator)

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

Default is a DefaultBeanNameGenerator.

setEnvironmentback to summary
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.

setResourceLoaderback to summary
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.

See Also
org.springframework.core.io.support.ResourcePatternResolver, org.springframework.core.io.support.PathMatchingResourcePatternResolver