public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccessor implements BeanDefinition, Cloneable
BeanDefinition
classes,
factoring out common properties of GenericBeanDefinition
,
RootBeanDefinition
, and ChildBeanDefinition
.
The autowire constants match the ones defined in the
AutowireCapableBeanFactory
interface.
GenericBeanDefinition
,
RootBeanDefinition
,
ChildBeanDefinition
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
AUTOWIRE_AUTODETECT
Deprecated.
as of Spring 3.0: If you are using mixed autowiring strategies,
use annotation-based autowiring for clearer demarcation of autowiring needs.
|
static int |
AUTOWIRE_BY_NAME
Constant that indicates autowiring bean properties by name.
|
static int |
AUTOWIRE_BY_TYPE
Constant that indicates autowiring bean properties by type.
|
static int |
AUTOWIRE_CONSTRUCTOR
Constant that indicates autowiring a constructor.
|
static int |
AUTOWIRE_NO
Constant that indicates no external autowiring at all.
|
static int |
DEPENDENCY_CHECK_ALL
Constant that indicates dependency checking for all properties
(object references as well as "simple" properties).
|
static int |
DEPENDENCY_CHECK_NONE
Constant that indicates no dependency check at all.
|
static int |
DEPENDENCY_CHECK_OBJECTS
Constant that indicates dependency checking for object references.
|
static int |
DEPENDENCY_CHECK_SIMPLE
Constant that indicates dependency checking for "simple" properties.
|
static String |
INFER_METHOD
Constant that indicates the container should attempt to infer the
destroy method name for a bean as opposed to
explicit specification of a method name. |
static String |
SCOPE_DEFAULT
Constant for the default scope name:
"" , equivalent to singleton
status unless overridden from a parent bean definition (if applicable). |
ROLE_APPLICATION, ROLE_INFRASTRUCTURE, ROLE_SUPPORT, SCOPE_PROTOTYPE, SCOPE_SINGLETON
Modifier | Constructor and Description |
---|---|
protected |
AbstractBeanDefinition()
Create a new AbstractBeanDefinition with default settings.
|
protected |
AbstractBeanDefinition(BeanDefinition original)
Create a new AbstractBeanDefinition as a deep copy of the given
bean definition.
|
protected |
AbstractBeanDefinition(ConstructorArgumentValues cargs,
MutablePropertyValues pvs)
Create a new AbstractBeanDefinition with the given
constructor argument values and property values.
|
Modifier and Type | Method and Description |
---|---|
void |
addQualifier(AutowireCandidateQualifier qualifier)
Register a qualifier to be used for autowire candidate resolution,
keyed by the qualifier's type name.
|
void |
applyDefaults(BeanDefinitionDefaults defaults)
Apply the provided default values to this bean.
|
Object |
clone()
Public declaration of Object's
clone() method. |
abstract AbstractBeanDefinition |
cloneBeanDefinition()
Clone this bean definition.
|
void |
copyQualifiersFrom(AbstractBeanDefinition source)
Copy the qualifiers from the supplied AbstractBeanDefinition to this bean definition.
|
boolean |
equals(Object other) |
int |
getAutowireMode()
Return the autowire mode as specified in the bean definition.
|
Class<?> |
getBeanClass()
Return the specified class of the bean definition (assuming it is resolved already).
|
String |
getBeanClassName()
Return the current bean class name of this bean definition.
|
ConstructorArgumentValues |
getConstructorArgumentValues()
Return constructor argument values for this bean (never
null ). |
int |
getDependencyCheck()
Return the dependency check code.
|
String[] |
getDependsOn()
Return the bean names that this bean depends on.
|
String |
getDescription()
Return a human-readable description of this bean definition.
|
String |
getDestroyMethodName()
Return the name of the destroy method.
|
String |
getFactoryBeanName()
Return the factory bean name, if any.
|
String |
getFactoryMethodName()
Return a factory method, if any.
|
String |
getInitMethodName()
Return the name of the initializer method.
|
Supplier<?> |
getInstanceSupplier()
Return a callback for creating an instance of the bean, if any.
|
Boolean |
getLazyInit()
Return whether this bean should be lazily initialized, i.e.
|
MethodOverrides |
getMethodOverrides()
Return information about methods to be overridden by the IoC
container.
|
BeanDefinition |
getOriginatingBeanDefinition()
Return the originating BeanDefinition, or
null if none. |
MutablePropertyValues |
getPropertyValues()
Return property values for this bean (never
null ). |
AutowireCandidateQualifier |
getQualifier(String typeName)
Return the qualifier mapped to the provided type name.
|
Set<AutowireCandidateQualifier> |
getQualifiers()
Return all registered qualifiers.
|
ResolvableType |
getResolvableType()
Return a resolvable type for this bean definition.
|
int |
getResolvedAutowireMode()
Return the resolved autowire code,
(resolving AUTOWIRE_AUTODETECT to AUTOWIRE_CONSTRUCTOR or AUTOWIRE_BY_TYPE).
|
Resource |
getResource()
Return the resource that this bean definition came from.
|
String |
getResourceDescription()
Return a description of the resource that this bean definition
came from (for the purpose of showing context in case of errors).
|
int |
getRole()
Return the role hint for this
BeanDefinition . |
String |
getScope()
Return the name of the target scope for the bean.
|
boolean |
hasBeanClass()
Return whether this definition specifies a bean class.
|
boolean |
hasConstructorArgumentValues()
Return if there are constructor argument values defined for this bean.
|
int |
hashCode() |
boolean |
hasMethodOverrides()
Return if there are method overrides defined for this bean.
|
boolean |
hasPropertyValues()
Return if there are property values values defined for this bean.
|
boolean |
hasQualifier(String typeName)
Return whether this bean has the specified qualifier.
|
boolean |
isAbstract()
Return whether this bean is "abstract", i.e.
|
boolean |
isAutowireCandidate()
Return whether this bean is a candidate for getting autowired into some other bean.
|
boolean |
isEnforceDestroyMethod()
Indicate whether the configured destroy method is the default.
|
boolean |
isEnforceInitMethod()
Indicate whether the configured initializer method is the default.
|
boolean |
isLazyInit()
Return whether this bean should be lazily initialized, i.e.
|
boolean |
isLenientConstructorResolution()
Return whether to resolve constructors in lenient mode or in strict mode.
|
boolean |
isNonPublicAccessAllowed()
Return whether to allow access to non-public constructors and methods.
|
boolean |
isPrimary()
Return whether this bean is a primary autowire candidate.
|
boolean |
isPrototype()
Return whether this a Prototype, with an independent instance
returned for each call.
|
boolean |
isSingleton()
Return whether this a Singleton, with a single shared instance
returned from all calls.
|
boolean |
isSynthetic()
Return whether this bean definition is 'synthetic', that is,
not defined by the application itself.
|
void |
overrideFrom(BeanDefinition other)
Override settings in this bean definition (presumably a copied parent
from a parent-child inheritance relationship) from the given bean
definition (presumably the child).
|
protected void |
prepareMethodOverride(MethodOverride mo)
Validate and prepare the given method override.
|
void |
prepareMethodOverrides()
Validate and prepare the method overrides defined for this bean.
|
Class<?> |
resolveBeanClass(ClassLoader classLoader)
Determine the class of the wrapped bean, resolving it from a
specified class name if necessary.
|
void |
setAbstract(boolean abstractFlag)
Set if this bean is "abstract", i.e.
|
void |
setAutowireCandidate(boolean autowireCandidate)
Set whether this bean is a candidate for getting autowired into some other bean.
|
void |
setAutowireMode(int autowireMode)
Set the autowire mode.
|
void |
setBeanClass(Class<?> beanClass)
Specify the class for this bean.
|
void |
setBeanClassName(String beanClassName)
Specify the bean class name of this bean definition.
|
void |
setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues)
Specify constructor argument values for this bean.
|
void |
setDependencyCheck(int dependencyCheck)
Set the dependency check code.
|
void |
setDependsOn(String... dependsOn)
Set the names of the beans that this bean depends on being initialized.
|
void |
setDescription(String description)
Set a human-readable description of this bean definition.
|
void |
setDestroyMethodName(String destroyMethodName)
Set the name of the destroy method.
|
void |
setEnforceDestroyMethod(boolean enforceDestroyMethod)
Specify whether or not the configured destroy method is the default.
|
void |
setEnforceInitMethod(boolean enforceInitMethod)
Specify whether or not the configured initializer method is the default.
|
void |
setFactoryBeanName(String factoryBeanName)
Specify the factory bean to use, if any.
|
void |
setFactoryMethodName(String factoryMethodName)
Specify a factory method, if any.
|
void |
setInitMethodName(String initMethodName)
Set the name of the initializer method.
|
void |
setInstanceSupplier(Supplier<?> instanceSupplier)
Specify a callback for creating an instance of the bean,
as an alternative to a declaratively specified factory method.
|
void |
setLazyInit(boolean lazyInit)
Set whether this bean should be lazily initialized.
|
void |
setLenientConstructorResolution(boolean lenientConstructorResolution)
Specify whether to resolve constructors in lenient mode (
true ,
which is the default) or to switch to strict resolution (throwing an exception
in case of ambiguous constructors that all match when converting the arguments,
whereas lenient mode would use the one with the 'closest' type matches). |
void |
setMethodOverrides(MethodOverrides methodOverrides)
Specify method overrides for the bean, if any.
|
void |
setNonPublicAccessAllowed(boolean nonPublicAccessAllowed)
Specify whether to allow access to non-public constructors and methods,
for the case of externalized metadata pointing to those.
|
void |
setOriginatingBeanDefinition(BeanDefinition originatingBd)
Set the originating (e.g.
|
void |
setPrimary(boolean primary)
Set whether this bean is a primary autowire candidate.
|
void |
setPropertyValues(MutablePropertyValues propertyValues)
Specify property values for this bean, if any.
|
void |
setResource(Resource resource)
Set the resource that this bean definition came from
(for the purpose of showing context in case of errors).
|
void |
setResourceDescription(String resourceDescription)
Set a description of the resource that this bean definition
came from (for the purpose of showing context in case of errors).
|
void |
setRole(int role)
Set the role hint for this
BeanDefinition . |
void |
setScope(String scope)
Set the name of the target scope for the bean.
|
void |
setSynthetic(boolean synthetic)
Set whether this bean definition is 'synthetic', that is, not defined
by the application itself (for example, an infrastructure bean such
as a helper for auto-proxying, created through
<aop:config> ). |
String |
toString() |
void |
validate()
Validate this bean definition.
|
addMetadataAttribute, getAttribute, getMetadataAttribute, getSource, removeAttribute, setAttribute, setSource
attributeNames, copyAttributesFrom, hasAttribute
finalize, getClass, notify, notifyAll, wait, wait, wait
getParentName, setParentName
attributeNames, getAttribute, hasAttribute, removeAttribute, setAttribute
getSource
public static final String SCOPE_DEFAULT
""
, equivalent to singleton
status unless overridden from a parent bean definition (if applicable).public static final int AUTOWIRE_NO
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_BY_NAME
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_BY_TYPE
setAutowireMode(int)
,
Constant Field Valuespublic static final int AUTOWIRE_CONSTRUCTOR
setAutowireMode(int)
,
Constant Field Values@Deprecated public static final int AUTOWIRE_AUTODETECT
setAutowireMode(int)
,
Constant Field Valuespublic static final int DEPENDENCY_CHECK_NONE
setDependencyCheck(int)
,
Constant Field Valuespublic static final int DEPENDENCY_CHECK_OBJECTS
setDependencyCheck(int)
,
Constant Field Valuespublic static final int DEPENDENCY_CHECK_SIMPLE
public static final int DEPENDENCY_CHECK_ALL
setDependencyCheck(int)
,
Constant Field Valuespublic static final String INFER_METHOD
destroy method name
for a bean as opposed to
explicit specification of a method name. The value "(inferred)" is specifically
designed to include characters otherwise illegal in a method name, ensuring
no possibility of collisions with legitimately named methods having the same
name.
Currently, the method names detected during destroy method inference are "close" and "shutdown", if present on the specific bean class.
protected AbstractBeanDefinition()
protected AbstractBeanDefinition(@Nullable ConstructorArgumentValues cargs, @Nullable MutablePropertyValues pvs)
protected AbstractBeanDefinition(BeanDefinition original)
original
- the original bean definition to copy frompublic void overrideFrom(BeanDefinition other)
abstract
, scope
,
lazyInit
, autowireMode
, dependencyCheck
,
and dependsOn
from the given bean definition.
constructorArgumentValues
, propertyValues
,
methodOverrides
from the given bean definition to existing ones.
factoryBeanName
, factoryMethodName
,
initMethodName
, and destroyMethodName
if specified
in the given bean definition.
public void applyDefaults(BeanDefinitionDefaults defaults)
defaults
- the default settings to applypublic void setBeanClassName(@Nullable String beanClassName)
@Nullable public String getBeanClassName()
getBeanClassName
in interface BeanDefinition
BeanDefinition.getParentName()
,
BeanDefinition.getFactoryBeanName()
,
BeanDefinition.getFactoryMethodName()
public void setBeanClass(@Nullable Class<?> beanClass)
setBeanClassName(String)
public Class<?> getBeanClass() throws IllegalStateException
NOTE: This is an initial class reference as declared in the bean metadata
definition, potentially combined with a declared factory method or a
FactoryBean
which may lead to a different
runtime type of the bean, or not being set at all in case of an instance-level
factory method (which is resolved via getFactoryBeanName()
instead).
Do not use this for runtime type introspection of arbitrary bean definitions.
The recommended way to find out about the actual runtime type of a particular bean
is a BeanFactory.getType(java.lang.String)
call for the
specified bean name; this takes all of the above cases into account and returns the
type of object that a BeanFactory.getBean(java.lang.String)
call is going to return for the same bean name.
null
)IllegalStateException
- if the bean definition does not define a bean class,
or a specified bean class name has not been resolved into an actual Class yetgetBeanClassName()
,
hasBeanClass()
,
setBeanClass(Class)
,
resolveBeanClass(ClassLoader)
public boolean hasBeanClass()
@Nullable public Class<?> resolveBeanClass(@Nullable ClassLoader classLoader) throws ClassNotFoundException
classLoader
- the ClassLoader to use for resolving a (potential) class nameClassNotFoundException
- if the class name could be resolvedpublic ResolvableType getResolvableType()
This implementation delegates to getBeanClass()
.
getResolvableType
in interface BeanDefinition
ResolvableType.NONE
)ConfigurableBeanFactory.getMergedBeanDefinition(java.lang.String)
public void setScope(@Nullable String scope)
The default is singleton status, although this is only applied once
a bean definition becomes active in the containing factory. A bean
definition may eventually inherit its scope from a parent bean definition.
For this reason, the default scope name is an empty string (i.e., ""
),
with singleton status being assumed until a resolved scope is set.
setScope
in interface BeanDefinition
BeanDefinition.SCOPE_SINGLETON
,
BeanDefinition.SCOPE_PROTOTYPE
@Nullable public String getScope()
getScope
in interface BeanDefinition
public boolean isSingleton()
isSingleton
in interface BeanDefinition
BeanDefinition.SCOPE_SINGLETON
public boolean isPrototype()
isPrototype
in interface BeanDefinition
BeanDefinition.SCOPE_PROTOTYPE
public void setAbstract(boolean abstractFlag)
Default is "false". Specify true to tell the bean factory to not try to instantiate that particular bean in any case.
public boolean isAbstract()
isAbstract
in interface BeanDefinition
public void setLazyInit(boolean lazyInit)
If false
, the bean will get instantiated on startup by bean
factories that perform eager initialization of singletons.
setLazyInit
in interface BeanDefinition
public boolean isLazyInit()
isLazyInit
in interface BeanDefinition
false
by default)@Nullable public Boolean getLazyInit()
null
otherwisepublic void setAutowireMode(int autowireMode)
autowireMode
- the autowire mode to set.
Must be one of the constants defined in this class.AUTOWIRE_NO
,
AUTOWIRE_BY_NAME
,
AUTOWIRE_BY_TYPE
,
AUTOWIRE_CONSTRUCTOR
,
AUTOWIRE_AUTODETECT
public int getAutowireMode()
public int getResolvedAutowireMode()
AUTOWIRE_AUTODETECT
,
AUTOWIRE_CONSTRUCTOR
,
AUTOWIRE_BY_TYPE
public void setDependencyCheck(int dependencyCheck)
dependencyCheck
- the code to set.
Must be one of the four constants defined in this class.DEPENDENCY_CHECK_NONE
,
DEPENDENCY_CHECK_OBJECTS
,
DEPENDENCY_CHECK_SIMPLE
,
DEPENDENCY_CHECK_ALL
public int getDependencyCheck()
public void setDependsOn(@Nullable String... dependsOn)
Note that dependencies are normally expressed through bean properties or constructor arguments. This property should just be necessary for other kinds of dependencies like statics (*ugh*) or database preparation on startup.
setDependsOn
in interface BeanDefinition
@Nullable public String[] getDependsOn()
getDependsOn
in interface BeanDefinition
public void setAutowireCandidate(boolean autowireCandidate)
Note that this flag is designed to only affect type-based autowiring. It does not affect explicit references by name, which will get resolved even if the specified bean is not marked as an autowire candidate. As a consequence, autowiring by name will nevertheless inject a bean if the name matches.
setAutowireCandidate
in interface BeanDefinition
AUTOWIRE_BY_TYPE
,
AUTOWIRE_BY_NAME
public boolean isAutowireCandidate()
isAutowireCandidate
in interface BeanDefinition
public void setPrimary(boolean primary)
If this value is true
for exactly one bean among multiple
matching candidates, it will serve as a tie-breaker.
setPrimary
in interface BeanDefinition
public boolean isPrimary()
isPrimary
in interface BeanDefinition
public void addQualifier(AutowireCandidateQualifier qualifier)
AutowireCandidateQualifier.getTypeName()
public boolean hasQualifier(String typeName)
@Nullable public AutowireCandidateQualifier getQualifier(String typeName)
public Set<AutowireCandidateQualifier> getQualifiers()
AutowireCandidateQualifier
objects.public void copyQualifiersFrom(AbstractBeanDefinition source)
source
- the AbstractBeanDefinition to copy frompublic void setInstanceSupplier(@Nullable Supplier<?> instanceSupplier)
If such a callback is set, it will override any other constructor or factory method metadata. However, bean property population and potential annotation-driven injection will still apply as usual.
@Nullable public Supplier<?> getInstanceSupplier()
public void setNonPublicAccessAllowed(boolean nonPublicAccessAllowed)
true
; switch this to false
for public access only.
This applies to constructor resolution, factory method resolution, and also init/destroy methods. Bean property accessors have to be public in any case and are not affected by this setting.
Note that annotation-driven configuration will still access non-public members as far as they have been annotated. This setting applies to externalized metadata in this bean definition only.
public boolean isNonPublicAccessAllowed()
public void setLenientConstructorResolution(boolean lenientConstructorResolution)
true
,
which is the default) or to switch to strict resolution (throwing an exception
in case of ambiguous constructors that all match when converting the arguments,
whereas lenient mode would use the one with the 'closest' type matches).public boolean isLenientConstructorResolution()
public void setFactoryBeanName(@Nullable String factoryBeanName)
setFactoryBeanName
in interface BeanDefinition
setFactoryMethodName(java.lang.String)
@Nullable public String getFactoryBeanName()
getFactoryBeanName
in interface BeanDefinition
public void setFactoryMethodName(@Nullable String factoryMethodName)
setFactoryMethodName
in interface BeanDefinition
setFactoryBeanName(java.lang.String)
,
setBeanClassName(java.lang.String)
@Nullable public String getFactoryMethodName()
getFactoryMethodName
in interface BeanDefinition
public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues)
public ConstructorArgumentValues getConstructorArgumentValues()
null
).getConstructorArgumentValues
in interface BeanDefinition
null
)public boolean hasConstructorArgumentValues()
hasConstructorArgumentValues
in interface BeanDefinition
public void setPropertyValues(MutablePropertyValues propertyValues)
public MutablePropertyValues getPropertyValues()
null
).getPropertyValues
in interface BeanDefinition
null
)public boolean hasPropertyValues()
hasPropertyValues
in interface BeanDefinition
public void setMethodOverrides(MethodOverrides methodOverrides)
public MethodOverrides getMethodOverrides()
Never returns null
.
public boolean hasMethodOverrides()
public void setInitMethodName(@Nullable String initMethodName)
The default is null
in which case there is no initializer method.
setInitMethodName
in interface BeanDefinition
@Nullable public String getInitMethodName()
getInitMethodName
in interface BeanDefinition
public void setEnforceInitMethod(boolean enforceInitMethod)
The default value is true
for a locally specified init method
but switched to false
for a shared setting in a defaults section
(e.g. bean init-method
versus beans default-init-method
level in XML) which might not apply to all contained bean definitions.
public boolean isEnforceInitMethod()
getInitMethodName()
public void setDestroyMethodName(@Nullable String destroyMethodName)
The default is null
in which case there is no destroy method.
setDestroyMethodName
in interface BeanDefinition
@Nullable public String getDestroyMethodName()
getDestroyMethodName
in interface BeanDefinition
public void setEnforceDestroyMethod(boolean enforceDestroyMethod)
The default value is true
for a locally specified destroy method
but switched to false
for a shared setting in a defaults section
(e.g. bean destroy-method
versus beans default-destroy-method
level in XML) which might not apply to all contained bean definitions.
public boolean isEnforceDestroyMethod()
getDestroyMethodName()
public void setSynthetic(boolean synthetic)
<aop:config>
).public boolean isSynthetic()
public void setRole(int role)
BeanDefinition
.setRole
in interface BeanDefinition
BeanDefinition.ROLE_APPLICATION
,
BeanDefinition.ROLE_SUPPORT
,
BeanDefinition.ROLE_INFRASTRUCTURE
public int getRole()
BeanDefinition
.getRole
in interface BeanDefinition
BeanDefinition.ROLE_APPLICATION
,
BeanDefinition.ROLE_SUPPORT
,
BeanDefinition.ROLE_INFRASTRUCTURE
public void setDescription(@Nullable String description)
setDescription
in interface BeanDefinition
@Nullable public String getDescription()
getDescription
in interface BeanDefinition
public void setResource(@Nullable Resource resource)
@Nullable public Resource getResource()
public void setResourceDescription(@Nullable String resourceDescription)
@Nullable public String getResourceDescription()
getResourceDescription
in interface BeanDefinition
public void setOriginatingBeanDefinition(BeanDefinition originatingBd)
@Nullable public BeanDefinition getOriginatingBeanDefinition()
null
if none.
Allows for retrieving the decorated bean definition, if any.
Note that this method returns the immediate originator. Iterate through the originator chain to find the original BeanDefinition as defined by the user.
getOriginatingBeanDefinition
in interface BeanDefinition
public void validate() throws BeanDefinitionValidationException
BeanDefinitionValidationException
- in case of validation failurepublic void prepareMethodOverrides() throws BeanDefinitionValidationException
BeanDefinitionValidationException
- in case of validation failureprotected void prepareMethodOverride(MethodOverride mo) throws BeanDefinitionValidationException
mo
- the MethodOverride object to validateBeanDefinitionValidationException
- in case of validation failurepublic Object clone()
clone()
method.
Delegates to cloneBeanDefinition()
.clone
in class Object
Object.clone()
public abstract AbstractBeanDefinition cloneBeanDefinition()
public boolean equals(@Nullable Object other)
equals
in class AttributeAccessorSupport
public int hashCode()
hashCode
in class AttributeAccessorSupport