Package org.springframework.test.context.aot

# Interface AotContextLoader

All Superinterfaces:
  `ContextLoader`, `SmartContextLoader`

All Known Implementing Classes:
  `AbstractDelegatingSmartContextLoader`, `AbstractGenericContextLoader`, `AbstractGenericWebContextLoader`, `AnnotationConfigContextLoader`, `AnnotationConfigWebContextLoader`, `DelegatingSmartContextLoader`, `GenericGroovyXmlContextLoader`, `GenericGroovyXmlWebContextLoader`, `GenericXmlContextLoader`, `GenericXmlWebContextLoader`, `WebDelegatingSmartContextLoader`

public interface AotContextLoader extends SmartContextLoader
Strategy interface for loading an `ApplicationContext` for build-time AOT processing as well as run-time AOT execution for an integration test managed by the Spring TestContext Framework.

`AotContextLoader` is an extension of the `SmartContextLoader` SPI that allows a context loader to optionally provide ahead-of-time (AOT) support.

As of Spring Framework 6.0, AOT infrastructure requires that an `AotContextLoader` create a `GenericApplicationContext` for both build-time processing and run-time execution.

Since:
  6.0
Author:
  Sam Brannen

## Method Summary

Modifier and Type
Method
Description
`default org.springframework.context.ApplicationContext`
`loadContextForAotProcessing(MergedContextConfiguration mergedConfig)`
Deprecated, for removal: This API element is subject to removal in a future version.
as of Spring Framework 6.2.4, in favor of `loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)`; to be removed in Spring Framework 8.0
`default org.springframework.context.ApplicationContext`
`loadContextForAotProcessing(MergedContextConfiguration mergedConfig, org.springframework.aot.hint.RuntimeHints runtimeHints)`
Load a new `ApplicationContext` for AOT build-time processing based on the supplied `MergedContextConfiguration`, configure the context, and return the context.
`org.springframework.context.ApplicationContext`
`loadContextForAotRuntime(MergedContextConfiguration mergedConfig, org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext> initializer)`
Load a new `ApplicationContext` for AOT run-time execution based on the supplied `MergedContextConfiguration` and `ApplicationContextInitializer`.

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

`loadContext, loadContext, processContextConfiguration, processLocations`

## Method Details

### loadContextForAotProcessing

@Deprecated(since="6.2.4", forRemoval=true) default org.springframework.context.ApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig) throws Exception
Deprecated, for removal: This API element is subject to removal in a future version.
as of Spring Framework 6.2.4, in favor of `loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)`; to be removed in Spring Framework 8.0
Load a new `ApplicationContext` for AOT build-time processing based on the supplied `MergedContextConfiguration`, configure the context, and return the context.

The default implementation of this method throws an `UnsupportedOperationException`. Note, however, that the framework invokes `loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)` as of Spring Framework 6.2.4.

Parameters:
  `mergedConfig` - the merged context configuration to use to load the application context
Returns:
  a new `GenericApplicationContext`
Throws:
  `ContextLoadException` - if context loading failed
  `Exception`
See Also:
  - `loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)`
  - `loadContextForAotRuntime(MergedContextConfiguration, ApplicationContextInitializer)`

### loadContextForAotProcessing

default org.springframework.context.ApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig, org.springframework.aot.hint.RuntimeHints runtimeHints) throws Exception
Load a new `ApplicationContext` for AOT build-time processing based on the supplied `MergedContextConfiguration`, configure the context, and return the context.

In contrast to `SmartContextLoader.loadContext(MergedContextConfiguration)`, this method must not refresh the `ApplicationContext` or register a JVM shutdown hook for it. Otherwise, this method should implement behavior identical to `loadContext(MergedContextConfiguration)`.

Any exception thrown while attempting to load an `ApplicationContext` should be wrapped in a `ContextLoadException`. Concrete implementations should therefore contain a try-catch block similar to the following.

     GenericApplicationContext context = // create context
     try {
         // configure context
     }
     catch (Exception ex) {
         throw new ContextLoadException(context, ex);
     }

For backward compatibility, the default implementation of this method delegates to `loadContextForAotProcessing(MergedContextConfiguration)`. Note, however, that the framework only invokes this method as of Spring Framework 6.2.4.

Parameters:
  `mergedConfig` - the merged context configuration to use to load the application context
  `runtimeHints` - the runtime hints
Returns:
  a new `GenericApplicationContext`
Throws:
  `ContextLoadException` - if context loading failed
  `Exception`
Since:
  6.2.4
See Also:
  - `loadContextForAotRuntime(MergedContextConfiguration, ApplicationContextInitializer)`

### loadContextForAotRuntime

org.springframework.context.ApplicationContext loadContextForAotRuntime(MergedContextConfiguration mergedConfig, org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext> initializer) throws Exception
Load a new `ApplicationContext` for AOT run-time execution based on the supplied `MergedContextConfiguration` and `ApplicationContextInitializer`.

This method must instantiate, initialize, and refresh the `ApplicationContext`.

Any exception thrown while attempting to load an `ApplicationContext` should be wrapped in a `ContextLoadException`. Concrete implementations should therefore contain a try-catch block similar to the following.

     GenericApplicationContext context = // create context
     try {
         // configure and refresh context
     }
     catch (Exception ex) {
         throw new ContextLoadException(context, ex);
     }

Parameters:
  `mergedConfig` - the merged context configuration to use to load the application context
  `initializer` - the `ApplicationContextInitializer` that should be applied to the context in order to recreate bean definitions
Returns:
  a new `GenericApplicationContext`
Throws:
  `ContextLoadException` - if context loading failed
  `Exception`
See Also:
  - `loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)`