Class AnnotationConfigContextLoader
- All Implemented Interfaces:
- AotContextLoader,- ContextLoader,- SmartContextLoader
AbstractGenericContextLoader that loads
 bean definitions from component classes.
 See the Javadoc for
 @ContextConfiguration
 for a definition of component class.
 
Note: AnnotationConfigContextLoader supports component classes
 rather than the String-based resource locations defined by the legacy
 ContextLoader API. Thus,
 although AnnotationConfigContextLoader extends
 AbstractGenericContextLoader, AnnotationConfigContextLoader
 does not support any String-based methods defined by
 AbstractContextLoader or AbstractGenericContextLoader.
 Consequently, AnnotationConfigContextLoader should chiefly be
 considered a SmartContextLoader
 rather than a ContextLoader.
- Since:
- 3.1
- Author:
- Sam Brannen
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected BeanDefinitionReaderAnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader.protected Class<?>[]detectDefaultConfigurationClasses(Class<?> declaringClass) Detect the default configuration classes for the supplied test class.protected String[]generateDefaultLocations(Class<?> clazz) AnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader.protected StringAnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader.protected voidloadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) Register classes in the suppliedcontextfrom the classes in the suppliedMergedContextConfiguration.protected String[]modifyLocations(Class<?> clazz, String... locations) AnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader.voidprocessContextConfiguration(ContextConfigurationAttributes configAttributes) Process component classes in the suppliedContextConfigurationAttributes.protected voidvalidateMergedContextConfiguration(MergedContextConfiguration mergedConfig) Ensure that the suppliedMergedContextConfigurationdoes not containlocations.Methods inherited from class org.springframework.test.context.support.AbstractGenericContextLoadercreateContext, customizeBeanFactory, customizeContext, loadContext, loadContext, loadContextForAotProcessing, loadContextForAotProcessing, loadContextForAotRuntime, prepareContextMethods inherited from class org.springframework.test.context.support.AbstractContextLoadercustomizeContext, getResourceSuffixes, isGenerateDefaultLocations, prepareContext, processLocationsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.test.context.SmartContextLoaderprocessLocations
- 
Constructor Details- 
AnnotationConfigContextLoaderpublic AnnotationConfigContextLoader()
 
- 
- 
Method Details- 
processContextConfigurationProcess component classes in the suppliedContextConfigurationAttributes.If the component classes are nullor empty andAbstractContextLoader.isGenerateDefaultLocations()returnstrue, thisSmartContextLoaderwill attempt todetect default configuration classes. If defaults are detected they will besetin the supplied configuration attributes. Otherwise, properties in the supplied configuration attributes will not be modified.- Specified by:
- processContextConfigurationin interface- SmartContextLoader
- Overrides:
- processContextConfigurationin class- AbstractContextLoader
- Parameters:
- configAttributes- the context configuration attributes to process
- See Also:
 
- 
detectDefaultConfigurationClassesDetect the default configuration classes for the supplied test class.The default implementation simply delegates to AnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(Class).- Parameters:
- declaringClass- the test class that declared- @ContextConfiguration
- Returns:
- an array of default configuration classes, potentially empty but
 never null
- See Also:
 
- 
modifyLocationsAnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader. Consequently, this method is not supported.- Overrides:
- modifyLocationsin class- AbstractContextLoader
- Parameters:
- clazz- the class with which the locations are associated
- locations- the resource locations to be modified
- Returns:
- an array of modified application context resource locations
- Throws:
- UnsupportedOperationException- in this implementation
- See Also:
 
- 
generateDefaultLocationsAnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader. Consequently, this method is not supported.- Overrides:
- generateDefaultLocationsin class- AbstractContextLoader
- Parameters:
- clazz- the class for which the default locations are to be generated
- Returns:
- an array of default application context resource locations
- Throws:
- UnsupportedOperationException- in this implementation
- See Also:
 
- 
getResourceSuffixAnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader. Consequently, this method is not supported.- Specified by:
- getResourceSuffixin class- AbstractContextLoader
- Returns:
- the resource suffix; never nullor empty
- Throws:
- UnsupportedOperationException- in this implementation
- See Also:
 
- 
validateMergedContextConfigurationEnsure that the suppliedMergedContextConfigurationdoes not containlocations.- Overrides:
- validateMergedContextConfigurationin class- AbstractGenericContextLoader
- Parameters:
- mergedConfig- the merged configuration to validate
- Since:
- 4.0.4
- See Also:
 
- 
loadBeanDefinitionsprotected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) Register classes in the suppliedcontextfrom the classes in the suppliedMergedContextConfiguration.Each class must represent a component class. An AnnotatedBeanDefinitionReaderis used to register the appropriate bean definitions.Note that this method does not call createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext)sinceAnnotatedBeanDefinitionReaderis not an instance ofBeanDefinitionReader.- Overrides:
- loadBeanDefinitionsin class- AbstractGenericContextLoader
- Parameters:
- context- the context in which the component classes should be registered
- mergedConfig- the merged configuration from which the classes should be retrieved
- See Also:
 
- 
createBeanDefinitionReaderAnnotationConfigContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader. Consequently, this method is not supported.- Specified by:
- createBeanDefinitionReaderin class- AbstractGenericContextLoader
- Parameters:
- context- the context for which the- BeanDefinitionReadershould be created
- Returns:
- a BeanDefinitionReaderfor the supplied context
- Throws:
- UnsupportedOperationException- in this implementation
- See Also:
 
 
-