クラス WebApplicationContextUtils

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

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

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

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

    • WebApplicationContextUtils

      public WebApplicationContextUtils()
  • メソッドの詳細

    • getRequiredWebApplicationContext

      public static WebApplicationContext getRequiredWebApplicationContext(ServletContextEE sc) throws IllegalStateExceptionSE
      この Web アプリのルート WebApplicationContext を見つけます。通常は ContextLoaderListener を介してロードされます。

      ルートコンテキストの起動時に発生した例外を再スローし、コンテキストの起動の失敗とコンテキストがないことを区別します。

      パラメーター:
      sc - ServletContext は、Web アプリケーションコンテキストを検索します
      戻り値:
      この Web アプリのルート WebApplicationContext
      例外:
      IllegalStateExceptionSE - ルート WebApplicationContext が見つからなかった場合
      関連事項:
    • getWebApplicationContext

      @Nullable public static WebApplicationContext getWebApplicationContext(ServletContextEE sc)
      この Web アプリのルート WebApplicationContext を見つけます。通常は ContextLoaderListener を介してロードされます。

      ルートコンテキストの起動時に発生した例外を再スローし、コンテキストの起動の失敗とコンテキストがないことを区別します。

      パラメーター:
      sc - ServletContext は、Web アプリケーションコンテキストを検索します
      戻り値:
      この Web アプリのルート WebApplicationContext、ない場合は null 
      関連事項:
    • getWebApplicationContext

      @Nullable public static WebApplicationContext getWebApplicationContext(ServletContextEE sc, StringSE attrName)
      この Web アプリのカスタム WebApplicationContext を見つけます。
      パラメーター:
      sc - ServletContext は、Web アプリケーションコンテキストを検索します
      attrName - 検索する ServletContext 属性の名前
      戻り値:
      この Web アプリに必要な WebApplicationContext、ない場合は null 
    • findWebApplicationContext

      @Nullable public static WebApplicationContext findWebApplicationContext(ServletContextEE 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 固有のスコープ(「リクエスト」、「セッション」、"globalSession" )を登録します。
      パラメーター:
      beanFactory - 設定する BeanFactory
    • registerWebApplicationScopes

      public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, @Nullable ServletContextEE sc)
      WebApplicationContext で使用されるように、指定された BeanFactory で Web 固有のスコープ(「リクエスト」、「セッション」、"globalSession"、「アプリケーション」)を登録します。
      パラメーター:
      beanFactory - 設定する BeanFactory
      sc - 実行している ServletContext
    • registerEnvironmentBeans

      public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, @Nullable ServletContextEE sc)
      WebApplicationContext で使用されるように、Web 固有の環境 Bean( "contextParameters"、"contextAttributes" )を指定の BeanFactory に登録します。
      パラメーター:
      bf - 設定する BeanFactory
      sc - 実行している ServletContext
    • registerEnvironmentBeans

      public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, @Nullable ServletContextEE servletContext, @Nullable ServletConfigEE servletConfig)
      WebApplicationContext で使用されるように、Web 固有の環境 Bean( "contextParameters"、"contextAttributes" )を指定の BeanFactory に登録します。
      パラメーター:
      bf - 設定する BeanFactory
      servletContext - 実行している ServletContext
      servletConfig - ServletConfig
    • initServletPropertySources

      public static void initServletPropertySources(MutablePropertySources propertySources, ServletContextEE servletContext)
      ServletConfigEE パラメーターに常に null を提供する initServletPropertySources(MutablePropertySources, ServletContext, ServletConfig) の便利なバリアント。
      関連事項:
    • initServletPropertySources

      public static void initServletPropertySources(MutablePropertySources sources, @Nullable ServletContextEE servletContext, @Nullable ServletConfigEE servletConfig)
      Servlet ベースの stub property sources を、指定された servletContext および servletConfig オブジェクトが入力された実際のインスタンスに置き換えます。

      このメソッドは、何度も呼び出される可能性があるという点でべき等ですが、スタブプロパティソースと対応する実際のプロパティソースの置換は 1 回だけ実行されます。

      パラメーター:
      sources - 初期化する MutablePropertySources (null であってはなりません)
      servletContext - 現在の ServletContextEE (null または servlet context property source がすでに初期化されている場合は無視されます)
      servletConfig - 現在の ServletConfigEE (null または servlet config property source がすでに初期化されている場合は無視されます)
      関連事項: