public class AnnotationConfigWebContextLoader extends AbstractGenericWebContextLoader
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 and Description |
---|
AnnotationConfigWebContextLoader() |
Modifier and Type | Method and Description |
---|---|
protected Class<?>[] |
detectDefaultConfigurationClasses(Class<?> declaringClass)
Detect the default configuration classes for the supplied test class.
|
protected String[] |
generateDefaultLocations(Class<?> clazz)
AnnotationConfigWebContextLoader should be used as a
SmartContextLoader ,
not as a legacy ContextLoader . |
protected String |
getResourceSuffix()
AnnotationConfigWebContextLoader should be used as a
SmartContextLoader ,
not as a legacy ContextLoader . |
protected void |
loadBeanDefinitions(GenericWebApplicationContext context,
WebMergedContextConfiguration webMergedConfig)
Register classes in the supplied context
from the classes in the supplied
WebMergedContextConfiguration . |
protected String[] |
modifyLocations(Class<?> clazz,
String... locations)
AnnotationConfigWebContextLoader should be used as a
SmartContextLoader ,
not as a legacy ContextLoader . |
void |
processContextConfiguration(ContextConfigurationAttributes configAttributes)
Process annotated classes in the supplied
ContextConfigurationAttributes . |
protected void |
validateMergedContextConfiguration(WebMergedContextConfiguration webMergedConfig)
Ensure that the supplied
WebMergedContextConfiguration does not
contain locations . |
configureWebResources, customizeBeanFactory, customizeContext, loadContext, loadContext
customizeContext, getResourceSuffixes, isGenerateDefaultLocations, prepareContext, processLocations
public void processContextConfiguration(ContextConfigurationAttributes configAttributes)
ContextConfigurationAttributes
.
If the annotated classes are null
or empty and
AbstractContextLoader.isGenerateDefaultLocations()
returns true
, this
SmartContextLoader
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.
processContextConfiguration
in interface SmartContextLoader
processContextConfiguration
in class AbstractContextLoader
configAttributes
- the context configuration attributes to processSmartContextLoader.processContextConfiguration(ContextConfigurationAttributes)
,
AbstractContextLoader.isGenerateDefaultLocations()
,
detectDefaultConfigurationClasses(Class)
protected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
The default implementation simply delegates to
AnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(Class)
.
declaringClass
- the test class that declared @ContextConfiguration
null
AnnotationConfigContextLoaderUtils
protected String[] modifyLocations(Class<?> clazz, String... locations)
AnnotationConfigWebContextLoader
should be used as a
SmartContextLoader
,
not as a legacy ContextLoader
.
Consequently, this method is not supported.modifyLocations
in class AbstractContextLoader
clazz
- the class with which the locations are associatedlocations
- the resource locations to be modifiedUnsupportedOperationException
- in this implementationAbstractContextLoader.modifyLocations(java.lang.Class<?>, java.lang.String...)
protected String[] generateDefaultLocations(Class<?> clazz)
AnnotationConfigWebContextLoader
should be used as a
SmartContextLoader
,
not as a legacy ContextLoader
.
Consequently, this method is not supported.generateDefaultLocations
in class AbstractContextLoader
clazz
- the class for which the default locations are to be generatedUnsupportedOperationException
- in this implementationAbstractContextLoader.generateDefaultLocations(java.lang.Class<?>)
protected String getResourceSuffix()
AnnotationConfigWebContextLoader
should be used as a
SmartContextLoader
,
not as a legacy ContextLoader
.
Consequently, this method is not supported.getResourceSuffix
in class AbstractContextLoader
null
or emptyUnsupportedOperationException
- in this implementationAbstractContextLoader.getResourceSuffix()
protected void loadBeanDefinitions(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig)
WebMergedContextConfiguration
.
Each class must represent an annotated class. An
AnnotatedBeanDefinitionReader
is used to register the appropriate
bean definitions.
loadBeanDefinitions
in class AbstractGenericWebContextLoader
context
- the context in which the annotated classes should be registeredwebMergedConfig
- the merged configuration from which the classes should be retrievedAbstractGenericWebContextLoader.loadBeanDefinitions(org.springframework.web.context.support.GenericWebApplicationContext, org.springframework.test.context.web.WebMergedContextConfiguration)
protected void validateMergedContextConfiguration(WebMergedContextConfiguration webMergedConfig)
WebMergedContextConfiguration
does not
contain locations
.validateMergedContextConfiguration
in class AbstractGenericWebContextLoader
webMergedConfig
- the merged configuration to validateAbstractGenericWebContextLoader.validateMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration)