Class OverrideMetadata

java.lang.Object
org.springframework.test.context.bean.override.OverrideMetadata

public abstract class OverrideMetadata extends Object
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 hashCodet 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 Details

  • Method Details

    • getBeanName

      protected String getBeanName()
      Return the bean name to override.
    • getBeanType

      public ResolvableType getBeanType()
      Return the bean type to override.
    • getField

      public Field getField()
      Return the annotated Field.
    • getStrategy

      public BeanOverrideStrategy getStrategy()
      Return the BeanOverrideStrategy 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 this OverrideMetadata, optionally provided with an existing BeanDefinition and/or an original instance, that is a singleton or an early wrapped instance.
      Parameters:
      beanName - the name of the bean being overridden
      existingBeanDefinition - an existing bean definition for that bean name, or null if not relevant
      existingBeanInstance - an existing instance for that bean name, for wrapping purposes, or null if irrelevant
      Returns:
      the instance with which to override the bean
    • track

      protected void track(Object override, SingletonBeanRegistry trackingBeanRegistry)
      Optionally track objects created by this OverrideMetadata.

      The default is not to track, but this can be overridden in subclasses.

      Parameters:
      override - the bean override instance to track
      trackingBeanRegistry - the registry in which trackers can optionally be registered
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object