public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor
BeanPostProcessor
のサブインターフェース。通常、特定のターゲット Bean のデフォルトのインスタンス化を抑制するために使用されます。たとえば、特別な TargetSources(ターゲットのプール、遅延初期化など)でプロキシを作成したり、フィールドインジェクションなどの追加のインジェクション戦略を実装したりします。
注意 : このインターフェースは、主にフレームワーク内で内部的に使用するための特別な目的のインターフェースです。可能な限りプレーンな BeanPostProcessor
インターフェースを実装することをお勧めします。
AbstractAutoProxyCreator.setCustomTargetSourceCreators(org.springframework.aop.framework.autoproxy.TargetSourceCreator...)
, LazyInitTargetSourceCreator
修飾子と型 | メソッドと説明 |
---|---|
default boolean | postProcessAfterInstantiation(ObjectSE bean, StringSE beanName) コンストラクターまたはファクトリメソッドを介して Bean がインスタンス化された後、Spring プロパティの設定(明示的なプロパティまたはオートワイヤーから)が発生する前に操作を実行します。 |
default ObjectSE | postProcessBeforeInstantiation(ClassSE<?> beanClass, StringSE beanName) ターゲット Bean がインスタンス化される前に、この BeanPostProcessor を適用します。 |
default PropertyValues | postProcessProperties(PropertyValues pvs, ObjectSE bean, StringSE beanName) ファクトリが特定の Bean に適用する前に、特定のプロパティ値を後処理します。プロパティ記述子は必要ありません。 |
default PropertyValues | postProcessPropertyValues(PropertyValues pvs, PropertyDescriptorSE[] pds, ObjectSE bean, StringSE beanName) 使用すべきではありません。 |
postProcessAfterInitialization, postProcessBeforeInitialization
@Nullable default ObjectSE postProcessBeforeInstantiation(ClassSE<?> beanClass, StringSE beanName) throws BeansException
このメソッドによって null 以外のオブジェクトが返された場合、Bean 作成プロセスは短絡されます。適用される追加の処理は、構成された BeanPostProcessors
からの BeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)
コールバックのみです。
このコールバックは、Bean クラスを持つ Bean 定義、および返された Bean 型がここに渡されるファクトリメソッド定義に適用されます。
ポストプロセッサーは、ここで返される Bean オブジェクトの型を予測するために、拡張 SmartInstantiationAwareBeanPostProcessor
インターフェースを実装できます。
デフォルトの実装は null
を返します。
beanClass
- インスタンス化される Bean のクラス beanName
- Bean の名前 null
BeansException
- エラーの場合 postProcessAfterInstantiation(java.lang.Object, java.lang.String)
, AbstractBeanDefinition.getBeanClass()
, AbstractBeanDefinition.getFactoryMethodName()
default boolean postProcessAfterInstantiation(ObjectSE bean, StringSE beanName) throws BeansException
これは、Spring のオートワイヤーが開始される直前の、指定された Bean インスタンスでカスタムフィールドインジェクションを実行するための理想的なコールバックです。
デフォルトの実装は true
を返します。
bean
- プロパティがまだ設定されていない状態で作成された Bean インスタンス beanName
- Bean の名前 true
。プロパティの入力をスキップする必要がある場合は false
。通常の実装では true
を返します。false
を返すと、後続の InstantiationAwareBeanPostProcessor インスタンスがこの Bean インスタンスで呼び出されなくなります。BeansException
- エラーの場合 postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)
@Nullable default PropertyValues postProcessProperties(PropertyValues pvs, ObjectSE bean, StringSE beanName) throws BeansException
実装は、カスタム postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
実装を提供する場合は null
(デフォルト)を返し、そうでない場合は pvs
を返す必要があります。このインターフェースの将来のバージョン(postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
が削除された)では、デフォルトの実装は、指定された pvs
をそのまま直接返します。
pvs
- ファクトリが適用しようとしているプロパティ値 (非 null
)bean
- Bean インスタンスは作成されましたが、そのプロパティはまだ設定されていません beanName
- Bean の名前 postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
の呼び出しを継続する null
(現在の Bean クラスに初期化された PropertyDescriptor
が必要)BeansException
- エラーの場合 postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
@DeprecatedSE @Nullable default PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptorSE[] pds, ObjectSE bean, StringSE beanName) throws BeansException
postProcessProperties(PropertyValues, Object, String)
に置き換えられました。また、通常は元の PropertyValues に基づいて新しい MutablePropertyValues インスタンスを作成し、特定の値を追加または削除して、適用するプロパティ値を置き換えることもできます。
デフォルトの実装は、指定された pvs
をそのまま返します。
pvs
- ファクトリが適用しようとしているプロパティ値 (非 null
)pds
- ターゲット Bean に関連するプロパティ記述子 (依存関係型が無視されている - ファクトリが特に処理する - すでに除外されている)bean
- Bean インスタンスは作成されましたが、そのプロパティはまだ設定されていません beanName
- Bean の名前 null
BeansException
- エラーの場合 postProcessProperties(org.springframework.beans.PropertyValues, java.lang.Object, java.lang.String)
, MutablePropertyValues