public abstract class AbstractBeanDefinitionReader extends Object implements EnvironmentCapable, BeanDefinitionReader
BeanDefinitionReader
interface.
Provides common properties like the bean factory to work on and the class loader to use for loading bean classes.
BeanDefinitionReaderUtils
Modifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger available to subclasses
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractBeanDefinitionReader(BeanDefinitionRegistry registry)
Create a new AbstractBeanDefinitionReader for the given bean factory.
|
Modifier and Type | Method and Description |
---|---|
ClassLoader |
getBeanClassLoader()
Return the class loader to use for bean classes.
|
BeanDefinitionRegistry |
getBeanFactory() |
BeanNameGenerator |
getBeanNameGenerator()
Return the BeanNameGenerator to use for anonymous beans
(without explicit bean name specified).
|
Environment |
getEnvironment()
Return the
Environment associated with this component. |
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(Resource... resources)
Load bean definitions from the specified resources.
|
int |
loadBeanDefinitions(String... locations)
Load bean definitions from the specified resource locations.
|
int |
loadBeanDefinitions(String location)
Load bean definitions from the specified resource location.
|
int |
loadBeanDefinitions(String location,
Set<Resource> actualResources)
Load bean definitions from the specified resource location.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
loadBeanDefinitions
protected final Log logger
protected AbstractBeanDefinitionReader(BeanDefinitionRegistry registry)
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 StandardEnvironment
. All ApplicationContext implementations are
EnvironmentCapable, while normal BeanFactory implementations are not.
registry
- the BeanFactory to load bean definitions into,
in the form of a BeanDefinitionRegistrysetResourceLoader(org.springframework.core.io.ResourceLoader)
,
setEnvironment(org.springframework.core.env.Environment)
public final BeanDefinitionRegistry getBeanFactory()
public final BeanDefinitionRegistry getRegistry()
BeanDefinitionReader
The factory is exposed through the BeanDefinitionRegistry interface, encapsulating the methods that are relevant for bean definition handling.
getRegistry
in interface BeanDefinitionReader
public void setResourceLoader(ResourceLoader resourceLoader)
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.
public ResourceLoader getResourceLoader()
BeanDefinitionReader
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.
getResourceLoader
in interface BeanDefinitionReader
BeanDefinitionReader.loadBeanDefinitions(String)
,
ResourcePatternResolver
public void setBeanClassLoader(ClassLoader beanClassLoader)
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).
Thread.getContextClassLoader()
public ClassLoader getBeanClassLoader()
BeanDefinitionReader
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).
getBeanClassLoader
in interface BeanDefinitionReader
public void setEnvironment(Environment environment)
public Environment getEnvironment()
EnvironmentCapable
Environment
associated with this component.getEnvironment
in interface EnvironmentCapable
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
Default is a DefaultBeanNameGenerator
.
public BeanNameGenerator getBeanNameGenerator()
BeanDefinitionReader
getBeanNameGenerator
in interface BeanDefinitionReader
public int loadBeanDefinitions(Resource... resources) throws BeanDefinitionStoreException
BeanDefinitionReader
loadBeanDefinitions
in interface BeanDefinitionReader
resources
- the resource descriptorsBeanDefinitionStoreException
- in case of loading or parsing errorspublic int loadBeanDefinitions(String location) throws BeanDefinitionStoreException
BeanDefinitionReader
The location can also be a location pattern, provided that the ResourceLoader of this bean definition reader is a ResourcePatternResolver.
loadBeanDefinitions
in interface BeanDefinitionReader
location
- the resource location, to be loaded with the ResourceLoader
(or ResourcePatternResolver) of this bean definition readerBeanDefinitionStoreException
- in case of loading or parsing errorsBeanDefinitionReader.getResourceLoader()
,
BeanDefinitionReader.loadBeanDefinitions(org.springframework.core.io.Resource)
,
BeanDefinitionReader.loadBeanDefinitions(org.springframework.core.io.Resource[])
public int loadBeanDefinitions(String location, Set<Resource> actualResources) throws BeanDefinitionStoreException
The location can also be a location pattern, provided that the ResourceLoader of this bean definition reader is a ResourcePatternResolver.
location
- the resource location, to be loaded with the ResourceLoader
(or ResourcePatternResolver) of this bean definition readeractualResources
- 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.BeanDefinitionStoreException
- in case of loading or parsing errorsgetResourceLoader()
,
BeanDefinitionReader.loadBeanDefinitions(org.springframework.core.io.Resource)
,
loadBeanDefinitions(org.springframework.core.io.Resource[])
public int loadBeanDefinitions(String... locations) throws BeanDefinitionStoreException
BeanDefinitionReader
loadBeanDefinitions
in interface BeanDefinitionReader
locations
- the resource locations, to be loaded with the ResourceLoader
(or ResourcePatternResolver) of this bean definition readerBeanDefinitionStoreException
- in case of loading or parsing errors