Package org.springframework.test.context.support

# Class AnnotationConfigContextLoader

java.lang.Object
org.springframework.test.context.support.AbstractContextLoader
org.springframework.test.context.support.AbstractGenericContextLoader
org.springframework.test.context.support.AnnotationConfigContextLoader

All Implemented Interfaces:
  `AotContextLoader`, `ContextLoader`, `SmartContextLoader`

public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
Concrete implementation of `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:
  - `processContextConfiguration(ContextConfigurationAttributes)`
  - `detectDefaultConfigurationClasses(Class)`
  - `loadBeanDefinitions(GenericApplicationContext, MergedContextConfiguration)`
  - `GenericXmlContextLoader`
  - `GenericGroovyXmlContextLoader`

## Constructor Summary

Constructors
Constructor
Description
`AnnotationConfigContextLoader()`

## Method Summary

Modifier and Type
Method
Description
`protected org.springframework.beans.factory.support.BeanDefinitionReader`
`createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext context)`
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`.
`protected Class<?>[]`
`detectDefaultConfigurationClasses(Class<?> declaringClass)`
Detect the default configuration classes for the supplied test class.
`protected String[]`
`generateDefaultLocations(Class<?> clazz)`
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`.
`protected String`
`getResourceSuffix()`
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`.
`protected void`
`loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext context, MergedContextConfiguration mergedConfig)`
Register classes in the supplied `context` from the classes in the supplied `MergedContextConfiguration`.
`protected String[]`
`modifyLocations(Class<?> clazz, String... locations)`
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`.
`void`
`processContextConfiguration(ContextConfigurationAttributes configAttributes)`
Process component classes in the supplied `ContextConfigurationAttributes`.
`protected void`
`validateMergedContextConfiguration(MergedContextConfiguration mergedConfig)`
Ensure that the supplied `MergedContextConfiguration` does not contain `locations`.

### Methods inherited from class org.springframework.test.context.support.AbstractGenericContextLoader

`createContext, customizeBeanFactory, customizeContext, loadContext, loadContext, loadContextForAotProcessing, loadContextForAotProcessing, loadContextForAotRuntime, prepareContext`

### Methods inherited from class org.springframework.test.context.support.AbstractContextLoader

`customizeContext, getResourceSuffixes, isGenerateDefaultLocations, prepareContext, processLocations`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.test.context.SmartContextLoader

`processLocations`

## Constructor Details

### AnnotationConfigContextLoader

public AnnotationConfigContextLoader()

## Method Details

### processContextConfiguration

public void processContextConfiguration(ContextConfigurationAttributes configAttributes)
Process component classes in the supplied `ContextConfigurationAttributes`.

If the component 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.

Specified by:
  `processContextConfiguration` in interface `SmartContextLoader`
Overrides:
  `processContextConfiguration` in class `AbstractContextLoader`
Parameters:
  `configAttributes` - the context configuration attributes to process
See Also:
  - `SmartContextLoader.processContextConfiguration(ContextConfigurationAttributes)`
  - `AbstractContextLoader.isGenerateDefaultLocations()`
  - `detectDefaultConfigurationClasses(Class)`

### detectDefaultConfigurationClasses

protected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
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:
  - `AnnotationConfigContextLoaderUtils`

### modifyLocations

protected String[] modifyLocations(Class<?> clazz, String... locations)
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`. Consequently, this method is not supported.

Overrides:
  `modifyLocations` in 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:
  - `AbstractContextLoader.modifyLocations(java.lang.Class<?>, java.lang.String...)`

### generateDefaultLocations

protected String[] generateDefaultLocations(Class<?> clazz)
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`. Consequently, this method is not supported.

Overrides:
  `generateDefaultLocations` in 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:
  - `AbstractContextLoader.generateDefaultLocations(java.lang.Class<?>)`

### getResourceSuffix

protected String getResourceSuffix()
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`. Consequently, this method is not supported.

Specified by:
  `getResourceSuffix` in class `AbstractContextLoader`
Returns:
  the resource suffix; never `null` or empty
Throws:
  `UnsupportedOperationException` - in this implementation
See Also:
  - `AbstractContextLoader.getResourceSuffix()`

### validateMergedContextConfiguration

protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig)
Ensure that the supplied `MergedContextConfiguration` does not contain `locations`.

Overrides:
  `validateMergedContextConfiguration` in class `AbstractGenericContextLoader`
Parameters:
  `mergedConfig` - the merged configuration to validate
Since:
  4.0.4
See Also:
  - `AbstractGenericContextLoader.validateMergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration)`

### loadBeanDefinitions

protected void loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext context, MergedContextConfiguration mergedConfig)
Register classes in the supplied `context` from the classes in the supplied `MergedContextConfiguration`.

Each class must represent a component class. An `AnnotatedBeanDefinitionReader` is used to register the appropriate bean definitions.

Note that this method does not call `createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext)` since `AnnotatedBeanDefinitionReader` is not an instance of `BeanDefinitionReader`.

Overrides:
  `loadBeanDefinitions` in 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:
  - `AbstractGenericContextLoader.loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext, org.springframework.test.context.MergedContextConfiguration)`

### createBeanDefinitionReader

protected org.springframework.beans.factory.support.BeanDefinitionReader createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext context)
`AnnotationConfigContextLoader` should be used as a `SmartContextLoader`, not as a legacy `ContextLoader`. Consequently, this method is not supported.

Specified by:
  `createBeanDefinitionReader` in class `AbstractGenericContextLoader`
Parameters:
  `context` - the context for which the `BeanDefinitionReader` should be created
Returns:
  a `BeanDefinitionReader` for the supplied context
Throws:
  `UnsupportedOperationException` - in this implementation
See Also:
  - `loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext, org.springframework.test.context.MergedContextConfiguration)`
  - `AbstractGenericContextLoader.createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext)`