クラス WebApplicationContextUtils
java.lang.ObjectSE
org.springframework.web.context.support.WebApplicationContextUtils
特定の
ServletContext のルート WebApplicationContext を取得するための便利なメソッドです。これは、カスタム Web ビューまたは MVC アクション内からプログラム的に Spring アプリケーションコンテキストにアクセスできます。多くの Web フレームワーク(Spring の一部、または外部ライブラリとして利用可能)のルートコンテキストにアクセスするより便利な方法があることに注意してください。このヘルパークラスは、ルートコンテキストにアクセスするための最も一般的な方法にすぎません。
- 作成者:
- Juergen Hoeller
- 関連事項:
コンストラクターの概要
コンストラクターメソッドのサマリー
修飾子と型メソッド説明static @Nullable WebApplicationContextfindWebApplicationContext(jakarta.servlet.ServletContext sc) この Web アプリの一意のWebApplicationContextを見つけます。ルート Web アプリのコンテキスト(推奨)または登録済みServletContext属性の中で一意のWebApplicationContext(通常、現在の Web アプリケーションの単一のDispatcherServletから取得)。static WebApplicationContextgetRequiredWebApplicationContext(jakarta.servlet.ServletContext sc) この Web アプリのルートWebApplicationContextを見つけます。通常はContextLoaderListenerを介してロードされます。static @Nullable WebApplicationContextgetWebApplicationContext(jakarta.servlet.ServletContext sc) この Web アプリのルートWebApplicationContextを見つけます。通常はContextLoaderListenerを介してロードされます。static @Nullable WebApplicationContextgetWebApplicationContext(jakarta.servlet.ServletContext sc, StringSE attrName) この Web アプリのカスタムWebApplicationContextを見つけます。static voidinitServletPropertySources(MutablePropertySources sources, @Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.ServletConfig servletConfig) Servletベースのstub property sourcesを、指定されたservletContextおよびservletConfigオブジェクトが入力された実際のインスタンスに置き換えます。static voidinitServletPropertySources(MutablePropertySources propertySources, jakarta.servlet.ServletContext servletContext) ServletConfigパラメーターに常にnullを提供するinitServletPropertySources(MutablePropertySources, ServletContext, ServletConfig)の便利なバリアントです。static voidregisterEnvironmentBeans(ConfigurableListableBeanFactory bf, @Nullable jakarta.servlet.ServletContext sc) WebApplicationContext で使用される、指定された BeanFactory とともに Web 固有の環境 Bean ( "contextParameters"、"contextAttributes" ) を登録します。static voidregisterEnvironmentBeans(ConfigurableListableBeanFactory bf, @Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.ServletConfig servletConfig) WebApplicationContext で使用される、指定された BeanFactory とともに Web 固有の環境 Bean ( "contextParameters"、"contextAttributes" ) を登録します。static voidWebApplicationContext で使用される、指定された BeanFactory に Web 固有のスコープ ("request" ,"session" ,"globalSession" ) を登録します。static voidregisterWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, @Nullable jakarta.servlet.ServletContext sc) WebApplicationContext で使用される、指定された BeanFactory に Web 固有のスコープ (「リクエスト」、「セッション」、"globalSession"、「アプリケーション」) を登録します。
コンストラクターの詳細
WebApplicationContextUtils
public WebApplicationContextUtils()
メソッドの詳細
getRequiredWebApplicationContext
public static WebApplicationContext getRequiredWebApplicationContext(jakarta.servlet.ServletContext sc) throws IllegalStateExceptionSE この Web アプリのルートWebApplicationContextを見つけます。通常はContextLoaderListenerを介してロードされます。ルートコンテキストの起動時に発生した例外を再スローし、コンテキストの起動の失敗とコンテキストがないことを区別します。
- パラメーター:
sc- ServletContext は、Web アプリケーションコンテキストを検索します- 戻り値:
- この Web アプリのルート WebApplicationContext
- 例外:
IllegalStateExceptionSE- ルート WebApplicationContext が見つからなかった場合- 関連事項:
getWebApplicationContext
public static @Nullable WebApplicationContext getWebApplicationContext(jakarta.servlet.ServletContext sc) この Web アプリのルートWebApplicationContextを見つけます。通常はContextLoaderListenerを介してロードされます。ルートコンテキストの起動時に発生した例外を再スローし、コンテキストの起動の失敗とコンテキストがないことを区別します。
- パラメーター:
sc- ServletContext は、Web アプリケーションコンテキストを検索します- 戻り値:
- この Web アプリのルート WebApplicationContext、ない場合は
null - 関連事項:
getWebApplicationContext
public static @Nullable WebApplicationContext getWebApplicationContext(jakarta.servlet.ServletContext sc, StringSE attrName) この Web アプリのカスタムWebApplicationContextを見つけます。- パラメーター:
sc- ServletContext は、Web アプリケーションコンテキストを検索しますattrName- 検索する ServletContext 属性の名前- 戻り値:
- この Web アプリに必要な WebApplicationContext、ない場合は
null
findWebApplicationContext
public static @Nullable WebApplicationContext findWebApplicationContext(jakarta.servlet.ServletContext sc) この Web アプリの一意のWebApplicationContextを見つけます。ルート Web アプリのコンテキスト(推奨)または登録済みServletContext属性の中で一意のWebApplicationContext(通常、現在の Web アプリケーションの単一のDispatcherServletから取得)。DispatcherServletのコンテキストの公開は、デフォルトではtrueであるpublishContextプロパティを介して制御できますが、Web アプリで複数のDispatcherServletを登録しても、単一のコンテキストのみを公開するように選択的に切り替えることができます。- パラメーター:
sc- ServletContext は、Web アプリケーションコンテキストを検索します- 戻り値:
- この Web アプリに必要な WebApplicationContext、ない場合は
null - 導入:
- 4.2
- 関連事項:
registerWebApplicationScopes
WebApplicationContext で使用される、指定された BeanFactory に Web 固有のスコープ ("request" ,"session" ,"globalSession" ) を登録します。- パラメーター:
beanFactory- 設定する BeanFactory
registerWebApplicationScopes
public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, @Nullable jakarta.servlet.ServletContext sc) WebApplicationContext で使用される、指定された BeanFactory に Web 固有のスコープ (「リクエスト」、「セッション」、"globalSession"、「アプリケーション」) を登録します。- パラメーター:
beanFactory- 設定する BeanFactorysc- 実行している ServletContext
registerEnvironmentBeans
public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, @Nullable jakarta.servlet.ServletContext sc) WebApplicationContext で使用される、指定された BeanFactory とともに Web 固有の環境 Bean ( "contextParameters"、"contextAttributes" ) を登録します。- パラメーター:
bf- 設定する BeanFactorysc- 実行している ServletContext
registerEnvironmentBeans
public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, @Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.ServletConfig servletConfig) WebApplicationContext で使用される、指定された BeanFactory とともに Web 固有の環境 Bean ( "contextParameters"、"contextAttributes" ) を登録します。- パラメーター:
bf- 設定する BeanFactoryservletContext- 実行している ServletContextservletConfig- ServletConfig
initServletPropertySources
public static void initServletPropertySources(MutablePropertySources propertySources, jakarta.servlet.ServletContext servletContext) ServletConfigパラメーターに常にnullを提供するinitServletPropertySources(MutablePropertySources, ServletContext, ServletConfig)の便利なバリアントです。- 関連事項:
initServletPropertySources
public static void initServletPropertySources(MutablePropertySources sources, @Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.ServletConfig servletConfig) Servletベースのstub property sourcesを、指定されたservletContextおよびservletConfigオブジェクトが入力された実際のインスタンスに置き換えます。このメソッドは、何度も呼び出される可能性があるという点でべき等ですが、スタブプロパティソースと対応する実際のプロパティソースの置換は 1 回だけ実行されます。
- パラメーター:
sources- 初期化するMutablePropertySources(nullであってはなりません)servletContext- 現在のServletContext(nullまたはservlet context property sourceがすでに初期化されている場合は無視されます)servletConfig- 現在のServletConfig(nullまたはservlet config property sourceがすでに初期化されている場合は無視されます)- 関連事項: