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