public abstract class AbstractContextLoader extends ObjectSE implements SmartContextLoader
ContextLoader
SPI のすべての具体的な実装の基礎を提供する抽象アプリケーションコンテキストローダー。processing
リソースの場所にテンプレートメソッドベースのアプローチを提供します。Spring 3.1 以降、AbstractContextLoader
は、SmartContextLoader
SPI のすべての具体的な実装の基礎も提供します。ContextLoader
SPI との下位互換性のために、processContextConfiguration(ContextConfigurationAttributes)
は processLocations(Class, String...)
に委譲します。
generateDefaultLocations(java.lang.Class<?>)
, getResourceSuffixes()
, modifyLocations(java.lang.Class<?>, java.lang.String...)
, prepareContext(org.springframework.context.ConfigurableApplicationContext, org.springframework.test.context.MergedContextConfiguration)
, customizeContext(org.springframework.context.ConfigurableApplicationContext, org.springframework.test.context.MergedContextConfiguration)
コンストラクターと説明 |
---|
AbstractContextLoader() |
修飾子と型 | メソッドと説明 |
---|---|
protected void | customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) Bean 定義がコンテキストになく、文脈をリフレッシュされる前にロードされた後、この ContextLoader によって作成された ConfigurableApplicationContext をカスタマイズします。 |
protected StringSE[] | generateDefaultLocations(ClassSE<?> clazz) 指定されたクラスに基づいて、デフォルトのクラスパスリソースの場所の配列を生成します。 |
protected abstract StringSE | getResourceSuffix() デフォルトの場所を検出するときに ApplicationContext リソースの場所に追加するサフィックスを取得します。 |
protected StringSE[] | getResourceSuffixes() デフォルトの場所を検出するときに ApplicationContext リソースの場所に追加するサフィックスを取得します。 |
protected boolean | isGenerateDefaultLocations() processLocations(Class, String...) に提供された locations が null または空の場合、デフォルトのリソースロケーションを生成する必要があるかどうかを決定します。 |
protected StringSE[] | modifyLocations(ClassSE<?> clazz, StringSE... locations) 指定された場所の配列の変更されたバージョンを生成し、それを返します。 |
protected void | prepareContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) Bean 定義が読み取られる前に、この SmartContextLoader によって作成された ConfigurableApplicationContext を準備します。 |
void | processContextConfiguration(ContextConfigurationAttributes configAttributes) ContextLoader SPI との下位互換性のために、デフォルトの実装は単に processLocations(Class, String...) に委譲し、渡された configuration attributes から取得した declaring class および resource locations を渡します。 |
StringSE[] | processLocations(ClassSE<?> clazz, StringSE... locations) 指定された locations が null または空で、isGenerateDefaultLocations() が true を返す場合、指定された class SE および構成されたリソースサフィックスのデフォルトの場所は generated (つまり、検出)です。それ以外の場合、提供された locations は必要に応じて変更されて返されます。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
loadContext
loadContext
public void processContextConfiguration(ContextConfigurationAttributes configAttributes)
ContextLoader
SPI との下位互換性のために、デフォルトの実装は単に processLocations(Class, String...)
に委譲し、渡された configuration attributes
から取得した declaring class
および resource locations
を渡します。処理された場所は、指定された構成属性の set
になります。サブクラスでオーバーライドできます。— たとえば、リソースの場所ではなく、アノテーション付きのクラスを処理します。
SmartContextLoader
の processContextConfiguration
configAttributes
- 処理するコンテキスト構成属性 processLocations(Class, String...)
protected void prepareContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig)
SmartContextLoader
によって作成された ConfigurableApplicationContext
を準備します。デフォルトの実装:
Environment
の指定された MergedContextConfiguration
からアクティブな Bean 定義プロファイルを設定します。PropertySources
と、指定された MergedContextConfiguration
からコンテキストの Environment
にインライン化されたプロパティを追加します。MergedContextConfiguration
を介して提供されたコンテキスト初期化クラス(存在する場合)を判別し、指定されたアプリケーションコンテキストでそれぞれインスタンス化して呼び出します。context
- 新しく作成されたアプリケーションコンテキスト mergedConfig
- マージされたコンテキスト構成 TestPropertySourceUtils.addPropertiesFilesToEnvironment(org.springframework.context.ConfigurableApplicationContext, java.lang.String...)
, TestPropertySourceUtils.addInlinedPropertiesToEnvironment(org.springframework.context.ConfigurableApplicationContext, java.lang.String...)
, ApplicationContextInitializer.initialize(ConfigurableApplicationContext)
, SmartContextLoader.loadContext(MergedContextConfiguration)
, ConfigurableApplicationContext.setId(java.lang.String)
protected void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig)
ContextLoader
によって作成された ConfigurableApplicationContext
をカスタマイズします。 デフォルトの実装は、提供された mergedConfig
に登録されているすべての context customizers
に委譲します。
context
- 新しく作成されたアプリケーションコンテキスト mergedConfig
- マージされたコンテキスト構成 public final StringSE[] processLocations(ClassSE<?> clazz, StringSE... locations)
locations
が null
または空で、isGenerateDefaultLocations()
が true
を返す場合、指定された class
SE および構成されたリソースサフィックスのデフォルトの場所は generated
(つまり、検出)です。それ以外の場合、提供された locations
は必要に応じて変更されて返されます。ContextLoader
の processLocations
clazz
- ロケーションが関連付けられているクラス: デフォルトのロケーションを生成するときに使用されます locations
- アプリケーションコンテキストのロードに使用する未変更の場所 (null
または空にすることができます)isGenerateDefaultLocations()
, generateDefaultLocations(Class)
, modifyLocations(Class, String...)
, ContextLoader.processLocations(Class, String...)
, processContextConfiguration(ContextConfigurationAttributes)
protected StringSE[] generateDefaultLocations(ClassSE<?> clazz)
例: 提供されたクラスが com.example.MyTest
の場合、生成された場所には値 "classpath:com/example/MyTest<suffix>"
の単一の文字列が含まれます。<suffix>
は、生成された場所が実際にクラスパスに存在する最初の構成済みリソースサフィックスの値です。
Spring 3.1 以降、このメソッドの実装は、SmartContextLoader
SPI で定義された規約に準拠しています。具体的には、このメソッドは、生成されたデフォルトの場所が実際に存在することを事前に検証します。存在しない場合、このメソッドは警告をログに記録し、空の配列を返します。
サブクラスはこのメソッドをオーバーライドして、異なるデフォルトの場所生成戦略を実装できます。
clazz
- デフォルトの場所が生成されるクラス getResourceSuffixes()
protected StringSE[] modifyLocations(ClassSE<?> clazz, StringSE... locations)
デフォルトの実装は、単に TestContextResourceUtils.convertToClasspathResourcePaths(java.lang.Class<?>, java.lang.String...)
に委譲するだけです。
サブクラスはこのメソッドをオーバーライドして、別の場所変更戦略を実装できます。
clazz
- 場所が関連付けられているクラス locations
- 変更するリソースの場所 protected boolean isGenerateDefaultLocations()
processLocations(Class, String...)
に提供された locations
が null
または空の場合、デフォルトのリソースロケーションを生成する必要があるかどうかを決定します。Spring 3.1 以降、このメソッドのセマンティクスはオーバーロードされ、デフォルトのリソースの場所またはデフォルトの構成クラスのいずれかの検出が含まれています。このメソッドは、processContextConfiguration(ContextConfigurationAttributes)
に提供される configuration attributes
に存在する classes
が null
または空である場合に、デフォルトの構成クラスを検出する必要があるかどうかを決定するためにも使用できます。
デフォルトの動作を変更するためにサブクラスでオーバーライドできます。
true
protected StringSE[] getResourceSuffixes()
ApplicationContext
リソースの場所に追加するサフィックスを取得します。 デフォルトの実装では、getResourceSuffix()
から返された値を単一要素の配列にラップするだけですが、複数のサフィックスをサポートするために、サブクラスによってオーバーライドできます。
null
または空にしない generateDefaultLocations(Class)
protected abstract StringSE getResourceSuffix()
ApplicationContext
リソースの場所に追加するサフィックスを取得します。 サブクラスは、単一のサフィックスを返すこのメソッドの実装を提供する必要があります。あるいは、複数のカスタムサフィックスを提供するために、サブクラスがこのメソッドの no-op 実装を提供し、getResourceSuffixes()
をオーバーライドする場合があります。
null
または空にしない generateDefaultLocations(Class)
, getResourceSuffixes()