public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport implements HandlerMapping, Ordered, BeanNameAware
HandlerMapping
実装の抽象基本クラス。順序付け、デフォルトハンドラー、パスパターンによってマッピングされたハンドラーインターセプタを含むハンドラーインターセプタをサポートします。 メモ: この基本クラスは、HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
の公開をサポートしていません。この属性のサポートは、通常リクエスト URL マッピングに基づいた具象サブクラスまでです。
getHandlerInternal(javax.servlet.http.HttpServletRequest)
, setDefaultHandler(java.lang.Object)
, setAlwaysUseFullPath(boolean)
, setUrlDecode(boolean)
, AntPathMatcher
, setInterceptors(java.lang.Object...)
, HandlerInterceptor
logger
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, LOOKUP_PATH, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
コンストラクターと説明 |
---|
AbstractHandlerMapping() |
修飾子と型 | メソッドと説明 |
---|---|
protected HandlerInterceptor | adaptInterceptor(ObjectSE interceptor) 指定されたインターセプターオブジェクトを HandlerInterceptor に適合させます。 |
protected void | detectMappedInterceptors(ListSE<HandlerInterceptor> mappedInterceptors) 型 MappedInterceptor の Bean を検出し、マッピングされたインターセプターのリストに追加します。 |
protected void | extendInterceptors(ListSE<ObjectSE> interceptors) 構成されたインターセプター( setInterceptors(java.lang.Object...) を参照)を指定すると、サブクラスがオーバーライドして追加のインターセプターを登録できる拡張フック。 |
protected StringSE | formatMappingName() |
protected HandlerInterceptor[] | getAdaptedInterceptors() 適応インターセプターを HandlerInterceptor 配列として返します。 |
protected CorsConfiguration | getCorsConfiguration(ObjectSE handler, HttpServletRequestEE request) 指定されたハンドラーの CORS 構成を取得します。 |
protected HandlerExecutionChain | getCorsHandlerExecutionChain(HttpServletRequestEE request, HandlerExecutionChain chain, CorsConfiguration config) CORS 関連の処理のために HandlerExecutionChain を更新します。 |
CorsProcessor | getCorsProcessor() 設定された CorsProcessor を返します。 |
ObjectSE | getDefaultHandler() このハンドラーマッピングのデフォルトハンドラーを返します。ない場合は null を返します。 |
HandlerExecutionChain | getHandler(HttpServletRequestEE request) 特定のリクエストのハンドラーを検索し、特定のハンドラーが見つからない場合はデフォルトのハンドラーにフォールバックします。 |
protected HandlerExecutionChain | getHandlerExecutionChain(ObjectSE handler, HttpServletRequestEE request) 該当するインターセプターを含む、指定されたハンドラー用の HandlerExecutionChain を作成します。 |
protected abstract ObjectSE | getHandlerInternal(HttpServletRequestEE request) 特定のリクエストのハンドラーを検索し、特定のリクエストが見つからない場合は null を返します。 |
protected MappedInterceptor[] | getMappedInterceptors() 構成されたすべての MappedInterceptor を配列として返します。 |
int | getOrder() このオブジェクトの順序値を取得します。 |
PathMatcher | getPathMatcher() 登録された URL パターンに対して URL パスを照合するために使用する PathMatcher 実装を返します。 |
UrlPathHelper | getUrlPathHelper() ルックアップパスの解決に使用する UrlPathHelper 実装を返します。 |
protected boolean | hasCorsConfigurationSource(ObjectSE handler) このハンドラーに CorsConfigurationSource がある場合、true を返します。 |
protected void | initApplicationContext() インターセプターを初期化します。 |
protected void | initInterceptors() WebRequestInterceptor を HandlerInterceptor に適応させる指定されたインターセプターを初期化します。 |
void | setAlwaysUseFullPath(boolean alwaysUseFullPath) 基になる UrlPathHelper の同じプロパティへのショートカット。 |
void | setBeanName(StringSE name) この Bean を作成した Bean ファクトリで Bean の名前を設定します。 |
void | setCorsConfigurations(MapSE<StringSE, CorsConfiguration> corsConfigurations) URL パターンに基づいて「グローバル」CORS 構成を設定します。 |
void | setCorsConfigurationSource(CorsConfigurationSource corsConfigurationSource) 「グローバル」CORS 構成ソースを設定します。 |
void | setCorsProcessor(CorsProcessor corsProcessor) 一致する CorsConfiguration をリクエストに適用するために使用するカスタム CorsProcessor を構成します。 |
void | setDefaultHandler(ObjectSE defaultHandler) このハンドラーマッピングのデフォルトハンドラーを設定します。 |
void | setInterceptors(ObjectSE... interceptors) このハンドラーマッピングによってマップされたすべてのハンドラーに適用するインターセプターを設定します。 |
void | setOrder(int order) この HandlerMapping Bean の順序値を指定します。 |
void | setPathMatcher(PathMatcher pathMatcher) 登録された URL パターンに対する URL パスのマッチングに使用する PathMatcher 実装を設定します。 |
void | setRemoveSemicolonContent(boolean removeSemicolonContent) 基になる UrlPathHelper の同じプロパティへのショートカット。 |
void | setUrlDecode(boolean urlDecode) 基になる UrlPathHelper の同じプロパティへのショートカット。 |
void | setUrlPathHelper(UrlPathHelper urlPathHelper) ルックアップパスの解決に使用する UrlPathHelper を設定します。 |
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public void setDefaultHandler(@Nullable ObjectSE defaultHandler)
デフォルトは null
で、デフォルトのハンドラーがないことを示します。
@Nullable public ObjectSE getDefaultHandler()
null
を返します。public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
UrlPathHelper
の同じプロパティへのショートカット。public void setUrlDecode(boolean urlDecode)
UrlPathHelper
の同じプロパティへのショートカット。public void setRemoveSemicolonContent(boolean removeSemicolonContent)
UrlPathHelper
の同じプロパティへのショートカット。public void setUrlPathHelper(UrlPathHelper urlPathHelper)
これを使用して、デフォルトの UrlPathHelper をカスタムサブクラスでオーバーライドするか、複数の HandlerMappings および MethodNameResolvers で共通の UrlPathHelper 設定を共有します。
public UrlPathHelper getUrlPathHelper()
public void setPathMatcher(PathMatcher pathMatcher)
AntPathMatcher
public PathMatcher getPathMatcher()
public void setInterceptors(ObjectSE... interceptors)
サポートされるインターセプター型は、HandlerInterceptor、WebRequestInterceptor、MappedInterceptor です。マップされたインターセプターは、そのパスパターンに一致するリクエスト URL にのみ適用されます。マップされたインターセプター Bean も、初期化中に型ごとに検出されます。
interceptors
- ハンドラーインターセプターの配列 adaptInterceptor(java.lang.Object)
, HandlerInterceptor
, WebRequestInterceptor
public void setCorsConfigurations(MapSE<StringSE,CorsConfiguration> corsConfigurations)
public void setCorsConfigurationSource(CorsConfigurationSource corsConfigurationSource)
setCorsConfigurations(Map)
public void setCorsProcessor(CorsProcessor corsProcessor)
CorsConfiguration
をリクエストに適用するために使用するカスタム CorsProcessor
を構成します。 デフォルトでは、DefaultCorsProcessor
が使用されます。
public CorsProcessor getCorsProcessor()
CorsProcessor
を返します。public void setOrder(int order)
デフォルト値は Ordered.LOWEST_PRECEDENCE
で、順序なしを意味します。
Ordered.getOrder()
public int getOrder()
Ordered
値が高いほど、優先度は低くなります。結果として、最も低い値を持つオブジェクトが最高の優先度を持ちます(サーブレット load-on-startup
の値に多少似ています)。
同じ順序の値は、影響を受けるオブジェクトの任意のソート位置になります。
Ordered
の getOrder
Ordered.HIGHEST_PRECEDENCE
, Ordered.LOWEST_PRECEDENCE
public void setBeanName(StringSE name)
BeanNameAware
通常の Bean プロパティの設定後、ただし InitializingBean.afterPropertiesSet()
またはカスタム init メソッドなどの init コールバックの前に呼び出されます。
BeanNameAware
の setBeanName
name
- ファクトリ内の Bean の名前。この名前は、ファクトリで使用される実際の Bean 名であり、最初に指定した名前とは異なる場合があります。特に内部 Bean 名の場合、実際の Bean 名は "#..." サフィックスを追加することで一意になります。必要に応じて、BeanFactoryUtils.originalBeanName(String)
メソッドを使用して、元の Bean 名(サフィックスなし)を抽出します。protected StringSE formatMappingName()
protected void initApplicationContext() throws BeansException
ApplicationObjectSupport
の initApplicationContext
ApplicationContextException
- 初期化エラーの場合 BeansException
- ApplicationContext メソッドによってスローされた場合 extendInterceptors(java.util.List)
, initInterceptors()
protected void extendInterceptors(ListSE<ObjectSE> interceptors)
setInterceptors(java.lang.Object...)
を参照)を指定すると、サブクラスがオーバーライドして追加のインターセプターを登録できる拡張フック。initInterceptors()
が指定されたインターセプターを HandlerInterceptor
インスタンスに適応させる前に呼び出されます。
デフォルトの実装は空です。
interceptors
- 構成されたインターセプターリスト(非 null
)。既存のインターセプターの前後にインターセプターを追加できます protected void detectMappedInterceptors(ListSE<HandlerInterceptor> mappedInterceptors)
MappedInterceptor
の Bean を検出し、マッピングされたインターセプターのリストに追加します。 これは、setInterceptors(java.lang.Object...)
を介して提供されたすべての MappedInterceptor
に加えて呼び出され、デフォルトで、現在のコンテキストとその祖先から型 MappedInterceptor
のすべての Bean を追加します。サブクラスはこのポリシーをオーバーライドおよび調整できます。
mappedInterceptors
- 追加する空のリスト protected void initInterceptors()
WebRequestInterceptor
を HandlerInterceptor
に適応させる指定されたインターセプターを初期化します。protected HandlerInterceptor adaptInterceptor(ObjectSE interceptor)
HandlerInterceptor
に適合させます。 デフォルトでは、サポートされるインターセプター型は HandlerInterceptor
および WebRequestInterceptor
です。指定された各 WebRequestInterceptor
は WebRequestHandlerInterceptorAdapter
でラップされます。
interceptor
- インターセプター HandlerInterceptor
, WebRequestInterceptor
, WebRequestHandlerInterceptorAdapter
@Nullable protected final HandlerInterceptor[] getAdaptedInterceptors()
HandlerInterceptor
配列として返します。HandlerInterceptor
の配列。ない場合は null
@Nullable protected final MappedInterceptor[] getMappedInterceptors()
MappedInterceptor
を配列として返します。MappedInterceptor
の配列。ない場合は null
@Nullable public final HandlerExecutionChain getHandler(HttpServletRequestEE request) throws ExceptionSE
HandlerMapping
の getHandler
request
- 現在の HTTP リクエスト ExceptionSE
- 内部エラーがある場合 getHandlerInternal(javax.servlet.http.HttpServletRequest)
@Nullable protected abstract ObjectSE getHandlerInternal(HttpServletRequestEE request) throws ExceptionSE
null
を返します。このメソッドは getHandler(javax.servlet.http.HttpServletRequest)
によって呼び出されます。null
の戻り値は、デフォルトのハンドラー(設定されている場合)につながります。CORS プリフライトリクエストでは、このメソッドはプリフライトリクエストではなく、URL パス、"Access-Control-Request-Method" ヘッダーからの HTTP メソッド、ヘッダーに基づいて予想される実際のリクエストに対して一致を返す必要があります "Access-Control-Request-Headers" ヘッダーから、getCorsConfiguration(Object, HttpServletRequest)
を介して CORS 設定を取得できるようにします。
メモ: このメソッドは、ハンドラーオブジェクトと動的に決定されたインターセプターを組み合わせて、事前に構築された HandlerExecutionChain
を返すこともあります。静的に指定されたインターセプターは、そのような既存のチェーンにマージされます。
request
- 現在の HTTP リクエスト null
ExceptionSE
- 内部エラーがある場合 protected HandlerExecutionChain getHandlerExecutionChain(ObjectSE handler, HttpServletRequestEE request)
HandlerExecutionChain
を作成します。 デフォルトの実装では、指定されたハンドラー、ハンドラーマッピングの共通インターセプター、現在のリクエスト URL に一致する MappedInterceptors
を使用して、標準の HandlerExecutionChain
を構築します。インターセプターは、登録された順に追加されます。サブクラスは、インターセプターのリストを継承 / 再配置するためにこれをオーバーライドできます。
注意 : 渡されたハンドラーオブジェクトは、生のハンドラーまたは事前に作成された HandlerExecutionChain
の場合があります。このメソッドは、新しい HandlerExecutionChain
の構築または既存のチェーンの拡張のいずれかで、これら 2 つのケースを明示的に処理する必要があります。
カスタムサブクラスにインターセプターを単純に追加するには、super.getHandlerExecutionChain(handler, request)
を呼び出し、返されたチェーンオブジェクトで HandlerExecutionChain.addInterceptor(org.springframework.web.servlet.HandlerInterceptor)
を呼び出すことを検討してください。
handler
- 解決されたハンドラーインスタンス (非 null
)request
- 現在の HTTP リクエスト null
)getAdaptedInterceptors()
protected boolean hasCorsConfigurationSource(ObjectSE handler)
CorsConfigurationSource
がある場合、true
を返します。@Nullable protected CorsConfiguration getCorsConfiguration(ObjectSE handler, HttpServletRequestEE request)
handler
- チェックするハンドラー(非 null
)。request
- 現在のリクエスト。null
protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequestEE request, HandlerExecutionChain chain, @Nullable CorsConfiguration config)
プリフライトリクエストの場合、デフォルトの実装は、選択されたハンドラーを、構成された setCorsProcessor(org.springframework.web.cors.CorsProcessor)
を呼び出す単純な HttpRequestHandler に置き換えます。
実際のリクエストの場合、デフォルトの実装は、CORS 関連のチェックを行い、CORS ヘッダーを追加する HandlerInterceptor を挿入します。
request
- 現在のリクエスト chain
- ハンドラーチェーン config
- 該当する CORS 設定 (おそらく null
)