类 AbstractContextLoader
- 所有已实现的接口:
ContextLoader,SmartContextLoader
- 直接已知子类:
AbstractGenericContextLoader,AbstractGenericWebContextLoader,InfraApplicationContextLoader
ContextLoader SPI. Provides a
Template Method based approach for processing
resource locations.
AbstractContextLoader also provides a basis
for all concrete implementations of the SmartContextLoader SPI. For
backwards compatibility with the ContextLoader SPI,
processContextConfiguration(ContextConfigurationAttributes) delegates
to processLocations(Class, String...).
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Juergen Hoeller, Phillip Webb, Harry Yang
- 另请参阅:
-
generateDefaultLocations(java.lang.Class<?>)getResourceSuffixes()modifyLocations(java.lang.Class<?>, java.lang.String...)prepareContext(cn.taketoday.context.ConfigurableApplicationContext, cn.taketoday.test.context.MergedContextConfiguration)customizeContext(cn.taketoday.context.ConfigurableApplicationContext, cn.taketoday.test.context.MergedContextConfiguration)
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidcustomizeContext(cn.taketoday.context.ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) Customize theConfigurableApplicationContextcreated by thisContextLoaderafter bean definitions have been loaded into the context but before the context has been refreshed.protected String[]generateDefaultLocations(Class<?> clazz) Generate the default classpath resource locations array based on the supplied class.protected abstract StringGet the suffix to append toApplicationContextresource locations when detecting default locations.protected String[]Get the suffixes to append toApplicationContextresource locations when detecting default locations.private voidinvokeApplicationContextInitializers(cn.taketoday.context.ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) protected booleanDetermine whether default resource locations should be generated if thelocationsprovided toprocessLocations(Class, String...)arenullor empty.protected String[]modifyLocations(Class<?> clazz, String... locations) Generate a modified version of the supplied locations array and return it.protected voidprepareContext(cn.taketoday.context.ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) Prepare theConfigurableApplicationContextcreated by thisSmartContextLoaderbefore bean definitions are read.voidprocessContextConfiguration(ContextConfigurationAttributes configAttributes) The default implementation processes locations analogous toprocessLocations(Class, String...), using thedeclaring classas the test class and theresource locationsretrieved from the suppliedconfiguration attributesas the locations to process.final String[]processLocations(Class<?> clazz, String... locations) If the suppliedlocationsarenullor empty andisGenerateDefaultLocations()returnstrue, default locations will begenerated(i.e., detected) for the specifiedclassand the configured resource suffixes; otherwise, the suppliedlocationswill be modified if necessary and returned.private String[]processLocationsInternal(Class<?> clazz, String... locations) 从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.test.context.SmartContextLoader
loadContext, loadContext
-
字段详细资料
-
log
private static final cn.taketoday.logging.Logger log -
SLASH
- 另请参阅:
-
EMPTY_STRING_ARRAY
-
-
构造器详细资料
-
AbstractContextLoader
public AbstractContextLoader()
-
-
方法详细资料
-
processContextConfiguration
The default implementation processes locations analogous toprocessLocations(Class, String...), using thedeclaring classas the test class and theresource locationsretrieved from the suppliedconfiguration attributesas the locations to process. The processed locations are thensetin the supplied configuration attributes.Can be overridden in subclasses — for example, to process annotated classes instead of resource locations.
- 指定者:
processContextConfiguration在接口中SmartContextLoader- 参数:
configAttributes- the context configuration attributes to process- 另请参阅:
-
prepareContext
protected void prepareContext(cn.taketoday.context.ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) Prepare theConfigurableApplicationContextcreated by thisSmartContextLoaderbefore bean definitions are read.The default implementation:
- Sets the active bean definition profiles from the supplied
MergedContextConfigurationin theEnvironmentof the context. - Adds
PropertySourcesfor all resource locations and inlined properties from the suppliedMergedContextConfigurationto theEnvironmentof the context. - Determines what (if any) context initializer classes have been supplied
via the
MergedContextConfigurationand instantiates and invokes each with the given application context.- Any
ApplicationContextInitializersimplementingOrderedor annotated with@Orderwill be sorted appropriately.
- Any
- 参数:
context- the newly created application contextmergedConfig- the merged context configuration- 另请参阅:
-
TestPropertySourceUtils.addPropertySourcesToEnvironment(ConfigurableApplicationContext, List)TestPropertySourceUtils.addInlinedPropertiesToEnvironment(cn.taketoday.context.ConfigurableApplicationContext, java.lang.String...)ApplicationContextInitializer.initialize(ConfigurableApplicationContext)SmartContextLoader.loadContext(MergedContextConfiguration)ConfigurableApplicationContext.setId(java.lang.String)
- Sets the active bean definition profiles from the supplied
-
invokeApplicationContextInitializers
private void invokeApplicationContextInitializers(cn.taketoday.context.ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) -
customizeContext
protected void customizeContext(cn.taketoday.context.ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) Customize theConfigurableApplicationContextcreated by thisContextLoaderafter bean definitions have been loaded into the context but before the context has been refreshed.The default implementation delegates to all
context customizersthat have been registered with the suppliedmergedConfig.- 参数:
context- the newly created application contextmergedConfig- the merged context configuration
-
processLocations
If the suppliedlocationsarenullor empty andisGenerateDefaultLocations()returnstrue, default locations will begenerated(i.e., detected) for the specifiedclassand the configured resource suffixes; otherwise, the suppliedlocationswill be modified if necessary and returned.- 指定者:
processLocations在接口中ContextLoader- 指定者:
processLocations在接口中SmartContextLoader- 参数:
clazz- the class with which the locations are associated: to be used when generating default locationslocations- the unmodified locations to use for loading the application context (can benullor empty)- 返回:
- a processed array of application context resource locations
- 另请参阅:
-
processLocationsInternal
-
generateDefaultLocations
Generate the default classpath resource locations array based on the supplied class.For example, if the supplied class is
com.example.MyTest, the generated locations will contain a single string with a value of"classpath:com/example/MyTest<suffix>", where<suffix>is the value of the first configured resource suffix for which the generated location actually exists in the classpath.The implementation of this method adheres to the contract defined in the
SmartContextLoaderSPI. Specifically, this method will preemptively verify that the generated default location actually exists. If it does not exist, this method will log a warning and return an empty array.Subclasses can override this method to implement a different default location generation strategy.
- 参数:
clazz- the class for which the default locations are to be generated- 返回:
- an array of default application context resource locations
- 另请参阅:
-
modifyLocations
Generate a modified version of the supplied locations array and return it.The default implementation simply delegates to
TestContextResourceUtils.convertToClasspathResourcePaths(java.lang.Class<?>, java.lang.String...).Subclasses can override this method to implement a different location modification strategy.
- 参数:
clazz- the class with which the locations are associatedlocations- the resource locations to be modified- 返回:
- an array of modified application context resource locations
-
isGenerateDefaultLocations
protected boolean isGenerateDefaultLocations()Determine whether default resource locations should be generated if thelocationsprovided toprocessLocations(Class, String...)arenullor empty.The semantics of this method have been overloaded to include detection of either default resource locations or default configuration classes. Consequently, this method can also be used to determine whether default configuration classes should be detected if the
classespresent in the configuration attributes supplied toprocessContextConfiguration(ContextConfigurationAttributes)arenullor empty.Can be overridden by subclasses to change the default behavior.
- 返回:
- always
trueby default
-
getResourceSuffixes
Get the suffixes to append toApplicationContextresource locations when detecting default locations.The default implementation simply wraps the value returned by
getResourceSuffix()in a single-element array, but this can be overridden by subclasses in order to support multiple suffixes.- 返回:
- the resource suffixes; never
nullor empty - 另请参阅:
-
getResourceSuffix
Get the suffix to append toApplicationContextresource locations when detecting default locations.Subclasses must provide an implementation of this method that returns a single suffix. Alternatively subclasses may provide a no-op implementation of this method and override
getResourceSuffixes()in order to provide multiple custom suffixes.- 返回:
- the resource suffix; never
nullor empty - 另请参阅:
-