クラス BeanOverrideHandler
警告 : 実装はキャッシュキーとして使用され、オーバーライドする Bean を識別するために使用される一意のメタデータセットに基づいて適切な equals()
および hashCode()
メソッドを実装する必要があります。オーバーライドされた equals()
および hashCode()
メソッドは、すべての Bean オーバーライドで使用される基本メタデータをサポートするために、このクラスの super
実装にも委譲する必要があります。さらに、診断を強化するために、実装で toString()
をオーバーライドして、関連するすべてのメタデータを含めることをお勧めします。
BeanOverrideHandler
の具体的な実装では、オーバーライドインスタンスの作成中に使用する追加のメタデータを保存できます (たとえば、アノテーション、アノテーション付きフィールド、アノテーション付きクラスの追加処理に基づいて保存できます)。
注意 : オーバーライドできるのはシングルトン Bean のみです。非シングルトン Bean をオーバーライドしようとすると、例外が発生します。
- 導入:
- 6.2
- 作成者:
- Simon Basl é , Stephane Nicoll, Sam Brannen
コンストラクターの概要
コンストラクター修飾子コンストラクター説明protected
BeanOverrideHandler
(FieldSE field, ResolvableType beanType, StringSE beanName, StringSE contextName, BeanOverrideStrategy strategy) Construct a newBeanOverrideHandler
from the supplied values.protected
BeanOverrideHandler
(FieldSE field, ResolvableType beanType, StringSE beanName, BeanOverrideStrategy strategy) 非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。メソッドのサマリー
修飾子と型メソッド説明protected abstract ObjectSE
createOverrideInstance
(StringSE beanName, BeanDefinition existingBeanDefinition, ObjectSE existingBeanInstance) このBeanOverrideHandler
のメタデータに基づいて、既存のBeanDefinition
または既存のシングルトン Bean の Bean オーバーライドインスタンスを作成します。boolean
static ListSE<BeanOverrideHandler>
forTestClass
(ClassSE<?> testClass) final StringSE
上書きする Bean 名を取得するか、型getBeanType()
の一致する単一の Bean を検索するためにnull
を取得します。final ResolvableType
オーバーライドする Bean 型を取得します。final StringSE
Get the name of the context hierarchy level in which this handler should be applied.final FieldSE
getField()
Get theField
SE annotated with@BeanOverride
。final BeanOverrideStrategy
このBeanOverrideHandler
のBeanOverrideStrategy
を取得します。これは、Bean オーバーライドインスタンスを作成する方法とタイミングに影響します。int
hashCode()
toString()
protected void
trackOverrideInstance
(ObjectSE override, SingletonBeanRegistry singletonBeanRegistry) このBeanOverrideHandler
によって作成された、提供された Bean オーバーライドインスタンスを追跡します。
コンストラクターの詳細
BeanOverrideHandler
@DeprecatedSE(since="6.2.6", forRemoval=true) protected BeanOverrideHandler(@Nullable FieldSE field, ResolvableType beanType, @Nullable StringSE beanName, BeanOverrideStrategy strategy) 非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。Spring Framework 6.2.6 以降、BeanOverrideHandler(Field, ResolvableType, String, String, BeanOverrideStrategy)
を推奨Construct a newBeanOverrideHandler
from the supplied values.To provide proper support for
@ContextHierarchy
, invokeBeanOverrideHandler(Field, ResolvableType, String, String, BeanOverrideStrategy)
instead.- パラメーター:
field
- theField
SE annotated with@BeanOverride
, ornull
if@BeanOverride
was declared at the type levelbeanType
- the type of bean to overridebeanName
- the name of the bean to override, ornull
to look for a single matching bean by typestrategy
- 使用するBeanOverrideStrategy
BeanOverrideHandler
protected BeanOverrideHandler(@Nullable FieldSE field, ResolvableType beanType, @Nullable StringSE beanName, StringSE contextName, BeanOverrideStrategy strategy) Construct a newBeanOverrideHandler
from the supplied values.- パラメーター:
field
- theField
SE annotated with@BeanOverride
, ornull
if@BeanOverride
was declared at the type levelbeanType
- the type of bean to overridebeanName
- the name of the bean to override, ornull
to look for a single matching bean by typecontextName
- the name of the context hierarchy level in which the handler should be applied, or an empty string to indicate that the handler should be applied to all application contexts within a context hierarchystrategy
- 使用するBeanOverrideStrategy
- 導入:
- 6.2.6
メソッドの詳細
forTestClass
指定されたtestClass
を処理し、テストクラスとその型階層の@BeanOverride
フィールドから派生した対応するBeanOverrideHandler
リストを構築します。このメソッドは、囲むクラス階層を検索せず、クラスまたはインターフェース上の
@BeanOverride
宣言を検索しません。- パラメーター:
testClass
- 処理するテストクラス- 戻り値:
- Bean オーバーライドハンドラーのリスト
- 関連事項:
findAllHandlers(Class)
getField
Get theField
SE annotated with@BeanOverride
。getBeanType
オーバーライドする Bean 型を取得します。getBeanName
上書きする Bean 名を取得するか、型getBeanType()
の一致する単一の Bean を検索するためにnull
を取得します。getContextName
Get the name of the context hierarchy level in which this handler should be applied.An empty string indicates that this handler should be applied to all application contexts.
If a context name is configured for this handler, it must match a name configured via
@ContextConfiguration(name=...)
.- 導入:
- 6.2.6
- 関連事項:
getStrategy
このBeanOverrideHandler
のBeanOverrideStrategy
を取得します。これは、Bean オーバーライドインスタンスを作成する方法とタイミングに影響します。createOverrideInstance
protected abstract ObjectSE createOverrideInstance(StringSE beanName, @Nullable BeanDefinition existingBeanDefinition, @Nullable ObjectSE existingBeanInstance) このBeanOverrideHandler
のメタデータに基づいて、既存のBeanDefinition
または既存のシングルトン Bean の Bean オーバーライドインスタンスを作成します。- パラメーター:
beanName
- 上書きされる Bean の名前existingBeanDefinition
- 指定された Bean 名に対する既存の Bean 定義、または利用できないか関連がない場合はnull
existingBeanInstance
- 折り返しの目的で提供された Bean 名の既存のインスタンス、または利用できないか関連がない場合はnull
- 戻り値:
- Bean をオーバーライドするインスタンス
- 関連事項:
trackOverrideInstance
protected void trackOverrideInstance(ObjectSE override, SingletonBeanRegistry singletonBeanRegistry) このBeanOverrideHandler
によって作成された、提供された Bean オーバーライドインスタンスを追跡します。デフォルトの実装では、提供されたインスタンスを追跡しませんが、必要に応じてサブクラスでオーバーライドできます。
- パラメーター:
override
- 追跡する Bean オーバーライドインスタンスsingletonBeanRegistry
- このハンドラーがシングルトン Bean の形式で追跡状態を保存できるレジストリ- 関連事項:
equals
hashCode
public int hashCode()toString
BeanOverrideHandler(Field, ResolvableType, String, String, BeanOverrideStrategy)
を推奨