Class OverrideMetadata
java.lang.Object
org.springframework.test.context.bean.override.OverrideMetadata
Metadata for Bean Override injection points, also responsible for the
creation of the overriding instance.
WARNING: implementations are used as a cache key and
must implement proper equals
and hashCode
t methods.
Specific implementations of metadata can have state to be used during override instance creation — for example, from further parsing of the annotation or the annotated field.
- Since:
- 6.2
- Author:
- Simon Baslé
-
Constructor Summary
ModifierConstructorDescriptionprotected
OverrideMetadata
(Field field, ResolvableType beanType, BeanOverrideStrategy strategy) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Object
createOverride
(String beanName, BeanDefinition existingBeanDefinition, Object existingBeanInstance) Create an override instance from thisOverrideMetadata
, optionally provided with an existingBeanDefinition
and/or an original instance, that is a singleton or an early wrapped instance.boolean
protected String
Return the bean name to override.Return the beantype
to override.getField()
Return the annotatedField
.Return theBeanOverrideStrategy
for this instance, as a hint on how and when the override instance should be created.int
hashCode()
toString()
protected void
track
(Object override, SingletonBeanRegistry trackingBeanRegistry) Optionally track objects created by thisOverrideMetadata
.
-
Constructor Details
-
OverrideMetadata
-
-
Method Details
-
getBeanName
Return the bean name to override. -
getBeanType
Return the beantype
to override. -
getField
Return the annotatedField
. -
getStrategy
Return theBeanOverrideStrategy
for this instance, as a hint on how and when the override instance should be created. -
createOverride
protected abstract Object createOverride(String beanName, @Nullable BeanDefinition existingBeanDefinition, @Nullable Object existingBeanInstance) Create an override instance from thisOverrideMetadata
, optionally provided with an existingBeanDefinition
and/or an original instance, that is a singleton or an early wrapped instance.- Parameters:
beanName
- the name of the bean being overriddenexistingBeanDefinition
- an existing bean definition for that bean name, ornull
if not relevantexistingBeanInstance
- an existing instance for that bean name, for wrapping purposes, ornull
if irrelevant- Returns:
- the instance with which to override the bean
-
track
Optionally track objects created by thisOverrideMetadata
.The default is not to track, but this can be overridden in subclasses.
- Parameters:
override
- the bean override instance to tracktrackingBeanRegistry
- the registry in which trackers can optionally be registered
-
equals
-
hashCode
public int hashCode() -
toString
-