public class ControllerAdviceBean extends ObjectSE implements Ordered
@ControllerAdvice Spring で管理される Bean に関する情報をカプセル化します。findAnnotatedBeans(ApplicationContext) メソッドを使用すると、このような Bean を検出できます。ただし、ControllerAdviceBean は、@ControllerAdvice アノテーションのないオブジェクトを含め、任意のオブジェクトから作成できます。
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| コンストラクターと説明 |
|---|
ControllerAdviceBean(ObjectSE bean) 指定された Bean インスタンスを使用して ControllerAdviceBean を作成します。 |
ControllerAdviceBean(StringSE beanName, BeanFactory beanFactory) 指定された Bean 名と BeanFactory を使用して ControllerAdviceBean を作成します。 |
ControllerAdviceBean(StringSE beanName, BeanFactory beanFactory, ControllerAdvice controllerAdvice) |
| 修飾子と型 | メソッドと説明 |
|---|---|
boolean | equals(ObjectSE other) |
static ListSE<ControllerAdviceBean> | findAnnotatedBeans(ApplicationContext context) 指定された ApplicationContext で @ControllerAdvice のアノテーションが付けられた Bean を見つけ、ControllerAdviceBean インスタンスとしてラップします。 |
ClassSE<?> | getBeanType() 含まれている Bean の型を返します。 |
int | getOrder() 含まれている Bean のオーダー値を取得します。 |
int | hashCode() |
boolean | isApplicableToBeanType(ClassSE<?> beanType) 指定された Bean 型がこの ControllerAdviceBean によって通知される必要があるかどうかを確認します。 |
ObjectSE | resolveBean() この ControllerAdviceBean の Bean インスタンスを取得します。必要に応じて、BeanFactory を介して Bean 名を解決します。 |
StringSE | toString() |
cloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSEpublic ControllerAdviceBean(ObjectSE bean)
ControllerAdviceBean を作成します。bean - Bean インスタンス public ControllerAdviceBean(StringSE beanName, BeanFactory beanFactory)
BeanFactory を使用して ControllerAdviceBean を作成します。beanName - Bean の名前 beanFactory - 最初に Bean 型を取得し、後で実際の Bean を解決する BeanFactory public ControllerAdviceBean(StringSE beanName, BeanFactory beanFactory, @Nullable ControllerAdvice controllerAdvice)
beanName - Bean の名前 beanFactory - 最初に Bean 型を取得し、後で実際の Bean を解決する BeanFactory controllerAdvice - Bean の @ControllerAdvice アノテーション、またはまだ取得されていない場合は null public int getOrder()
Spring Framework 5.2 以降、オーダー値は次のアルゴリズムを使用して遅延検索され、キャッシュされます。ただし、スコープ付き Bean として構成されている @ControllerAdvice Bean- たとえば、リクエストスコープまたはセッションスコープの Bean として - 先行して解決されることはありません。Ordered は、スコープ付き @ControllerAdvice Bean には適用されません。
Ordered を実装している場合は、Ordered.getOrder() から返された値を使用します。Ordered.LOWEST_PRECEDENCE をデフォルトのオーダー値として使用し、OrderUtils.getOrder(Class, int) から返された値を使用します。Ordered.LOWEST_PRECEDENCE を使用します。Ordered の getOrder resolveBean()@Nullable public ClassSE<?> getBeanType()
Bean 型が CGLIB 生成クラスである場合、元のユーザー定義クラスが返されます。
public ObjectSE resolveBean()
ControllerAdviceBean の Bean インスタンスを取得します。必要に応じて、BeanFactory を介して Bean 名を解決します。Spring Framework 5.2 の時点で、Bean インスタンスが解決されると、それがシングルトンの場合はキャッシュされるため、BeanFactory での繰り返しのルックアップが回避されます。
public boolean isApplicableToBeanType(@Nullable ClassSE<?> beanType)
ControllerAdviceBean によって通知される必要があるかどうかを確認します。beanType - チェックする Bean の型 ControllerAdvicepublic int hashCode()
ObjectSE の hashCodeSE public StringSE toString()
ObjectSE の toStringSE public static ListSE<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context)
ApplicationContext で @ControllerAdvice のアノテーションが付けられた Bean を見つけ、ControllerAdviceBean インスタンスとしてラップします。Spring Framework 5.2 の時点で、返されるリスト内の ControllerAdviceBean インスタンスは、OrderComparator.sort(List) を使用してソートされます。
getOrder(), OrderComparator, Ordered