Class BeanOverrideHandler
WARNING: Implementations are used as a cache key and must
 implement proper equals() and hashCode() methods based on the
 unique set of metadata used to identify the bean to override. Overridden
 equals() and hashCode() methods should also delegate to the
 super implementations in this class in order to support the basic
 metadata used by all bean overrides. In addition, it is recommended that
 implementations override toString() to include all relevant metadata
 in order to enhance diagnostics.
 
Concrete implementations of BeanOverrideHandler can store additional
 metadata to use during override instance
 creation — for example, based on further processing of the annotation,
 the annotated field, or the annotated class.
 
NOTE: Only singleton beans can be overridden. Any attempt to override a non-singleton bean will result in an exception.
- Since:
- 6.2
- Author:
- Simon Baslé, Stephane Nicoll, Sam Brannen
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedBeanOverrideHandler(@Nullable Field field, ResolvableType beanType, @Nullable String beanName, BeanOverrideStrategy strategy) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract ObjectcreateOverrideInstance(String beanName, @Nullable BeanDefinition existingBeanDefinition, @Nullable Object existingBeanInstance) Create a bean override instance for an existingBeanDefinitionor an existing singleton bean, based on the metadata in thisBeanOverrideHandler.booleanstatic List<BeanOverrideHandler>forTestClass(Class<?> testClass) Process the giventestClassand build the correspondingBeanOverrideHandlerlist derived from@BeanOverridefields in the test class and its type hierarchy.Get the bean name to override, ornullto look for a single matching bean of typegetBeanType().final ResolvableTypeGet the bean type to override.getField()Get the annotatedField.final BeanOverrideStrategyGet theBeanOverrideStrategyfor thisBeanOverrideHandler, which influences how and when the bean override instance should be created.inthashCode()toString()protected voidtrackOverrideInstance(Object override, SingletonBeanRegistry singletonBeanRegistry) Track the supplied bean override instance that was created by thisBeanOverrideHandler.
- 
Constructor Details- 
BeanOverrideHandlerprotected BeanOverrideHandler(@Nullable Field field, ResolvableType beanType, @Nullable String beanName, BeanOverrideStrategy strategy) 
 
- 
- 
Method Details- 
forTestClassProcess the giventestClassand build the correspondingBeanOverrideHandlerlist derived from@BeanOverridefields in the test class and its type hierarchy.This method does not search the enclosing class hierarchy and does not search for @BeanOverridedeclarations on classes or interfaces.- Parameters:
- testClass- the test class to process
- Returns:
- a list of bean override handlers
- See Also:
- 
- findAllHandlers(Class)
 
 
- 
getFieldGet the annotatedField.
- 
getBeanTypeGet the bean type to override.
- 
getBeanNameGet the bean name to override, ornullto look for a single matching bean of typegetBeanType().
- 
getStrategyGet theBeanOverrideStrategyfor thisBeanOverrideHandler, which influences how and when the bean override instance should be created.
- 
createOverrideInstanceprotected abstract Object createOverrideInstance(String beanName, @Nullable BeanDefinition existingBeanDefinition, @Nullable Object existingBeanInstance) Create a bean override instance for an existingBeanDefinitionor an existing singleton bean, based on the metadata in thisBeanOverrideHandler.- Parameters:
- beanName- the name of the bean being overridden
- existingBeanDefinition- an existing bean definition for the supplied bean name, or- nullif not available or not relevant
- existingBeanInstance- an existing instance for the supplied bean name for wrapping purposes, or- nullif not available or not relevant
- Returns:
- the instance with which to override the bean
- See Also:
 
- 
trackOverrideInstanceTrack the supplied bean override instance that was created by thisBeanOverrideHandler.The default implementation does not track the supplied instance, but this can be overridden in subclasses as appropriate. - Parameters:
- override- the bean override instance to track
- singletonBeanRegistry- a registry in which this handler can store tracking state in the form of a singleton bean
- See Also:
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
 
-