クラス WebApplicationContextUtils

java.lang.ObjectSE
org.springframework.web.context.support.WebApplicationContextUtils

public abstract class WebApplicationContextUtils extends ObjectSE
特定の ServletContext のルート WebApplicationContext を取得するための便利なメソッドです。これは、カスタム Web ビューまたは MVC アクション内からプログラム的に Spring アプリケーションコンテキストにアクセスできます。

多くの Web フレームワーク(Spring の一部、または外部ライブラリとして利用可能)のルートコンテキストにアクセスするより便利な方法があることに注意してください。このヘルパークラスは、ルートコンテキストにアクセスするための最も一般的な方法にすぎません。

作成者:
Juergen Hoeller
関連事項:
  • コンストラクターの詳細

    • 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

      public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory)
      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 - 設定する BeanFactory
      sc - 実行している ServletContext
    • registerEnvironmentBeans

      public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, @Nullable jakarta.servlet.ServletContext sc)
      WebApplicationContext で使用される、指定された BeanFactory とともに Web 固有の環境 Bean ( "contextParameters"、"contextAttributes" ) を登録します。
      パラメーター:
      bf - 設定する BeanFactory
      sc - 実行している 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 - 設定する BeanFactory
      servletContext - 実行している ServletContext
      servletConfig - 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 がすでに初期化されている場合は無視されます)
      関連事項: