Class AnnotationConfigWebContextLoader
- All Implemented Interfaces:
ContextLoader
,SmartContextLoader
AbstractGenericWebContextLoader
that loads
bean definitions from annotated classes.
See the Javadoc for
@ContextConfiguration
for a definition of annotated class.
Note: AnnotationConfigWebContextLoader
supports annotated classes
rather than the String-based resource locations defined by the legacy
ContextLoader
API. Thus,
although AnnotationConfigWebContextLoader
extends
AbstractGenericWebContextLoader
, AnnotationConfigWebContextLoader
does not support any String-based methods defined by
AbstractContextLoader
or AbstractGenericWebContextLoader
.
Consequently, AnnotationConfigWebContextLoader
should chiefly be
considered a SmartContextLoader
rather than a ContextLoader
.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?>[]
detectDefaultConfigurationClasses
(Class<?> declaringClass) Detect the default configuration classes for the supplied test class.protected String[]
generateDefaultLocations
(Class<?> clazz) AnnotationConfigWebContextLoader
should be used as aSmartContextLoader
, not as a legacyContextLoader
.protected String
AnnotationConfigWebContextLoader
should be used as aSmartContextLoader
, not as a legacyContextLoader
.protected void
loadBeanDefinitions
(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Register classes in the supplied context from the classes in the suppliedWebMergedContextConfiguration
.protected String[]
modifyLocations
(Class<?> clazz, String... locations) AnnotationConfigWebContextLoader
should be used as aSmartContextLoader
, not as a legacyContextLoader
.void
processContextConfiguration
(ContextConfigurationAttributes configAttributes) Process annotated classes in the suppliedContextConfigurationAttributes
.protected void
validateMergedContextConfiguration
(WebMergedContextConfiguration webMergedConfig) Ensure that the suppliedWebMergedContextConfiguration
does not containlocations
.Methods inherited from class org.springframework.test.context.web.AbstractGenericWebContextLoader
configureWebResources, customizeBeanFactory, customizeContext, loadContext, loadContext
Methods inherited from class org.springframework.test.context.support.AbstractContextLoader
customizeContext, getResourceSuffixes, isGenerateDefaultLocations, prepareContext, processLocations
-
Constructor Details
-
AnnotationConfigWebContextLoader
public AnnotationConfigWebContextLoader()
-
-
Method Details
-
processContextConfiguration
Process annotated classes in the suppliedContextConfigurationAttributes
.If the annotated classes are
null
or empty andAbstractContextLoader.isGenerateDefaultLocations()
returnstrue
, thisSmartContextLoader
will attempt to detect default configuration classes. If defaults are detected they will be set in the supplied configuration attributes. Otherwise, properties in the supplied configuration attributes will not be modified.- Specified by:
processContextConfiguration
in interfaceSmartContextLoader
- Overrides:
processContextConfiguration
in classAbstractContextLoader
- Parameters:
configAttributes
- the context configuration attributes to process- See Also:
-
detectDefaultConfigurationClasses
Detect 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:
-
modifyLocations
AnnotationConfigWebContextLoader
should be used as aSmartContextLoader
, not as a legacyContextLoader
. Consequently, this method is not supported.- Overrides:
modifyLocations
in classAbstractContextLoader
- Parameters:
clazz
- the class with which the locations are associatedlocations
- the resource locations to be modified- Returns:
- an array of modified application context resource locations
- Throws:
UnsupportedOperationException
- in this implementation- See Also:
-
generateDefaultLocations
AnnotationConfigWebContextLoader
should be used as aSmartContextLoader
, not as a legacyContextLoader
. Consequently, this method is not supported.- Overrides:
generateDefaultLocations
in classAbstractContextLoader
- 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:
-
getResourceSuffix
AnnotationConfigWebContextLoader
should be used as aSmartContextLoader
, not as a legacyContextLoader
. Consequently, this method is not supported.- Specified by:
getResourceSuffix
in classAbstractContextLoader
- Returns:
- the resource suffix; never
null
or empty - Throws:
UnsupportedOperationException
- in this implementation- See Also:
-
loadBeanDefinitions
protected void loadBeanDefinitions(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Register classes in the supplied context from the classes in the suppliedWebMergedContextConfiguration
.Each class must represent an annotated class. An
AnnotatedBeanDefinitionReader
is used to register the appropriate bean definitions.- Specified by:
loadBeanDefinitions
in classAbstractGenericWebContextLoader
- Parameters:
context
- the context in which the annotated classes should be registeredwebMergedConfig
- the merged configuration from which the classes should be retrieved- See Also:
-
validateMergedContextConfiguration
Ensure that the suppliedWebMergedContextConfiguration
does not containlocations
.- Overrides:
validateMergedContextConfiguration
in classAbstractGenericWebContextLoader
- Parameters:
webMergedConfig
- the merged configuration to validate- Since:
- 4.0.4
- See Also:
-