Browse Source
This commit introduces a dedicated AotContextLoader extension of SmartContextLoader and reverts the recent changes to the existing contract for SmartContextLoader. This allows existing SmartContextLoader implementations to continue working unaffected by AOT support unless they opt into AOT support by explicitly implementing the new AotContextLoader contract. In addition, existing SmartContextLoader implementations in the spring-test module have been modified to implement AotContextLoader instead of SmartContextLoader. This allows the core framework to provide built-in AOT support in the TestContext framework, and it also allows third-party extensions to built-in SmartContextLoaders to participate in AOT processing and run-time support transparently (or at least as transparent as possible). Closes gh-28906pull/28958/head
7 changed files with 216 additions and 67 deletions
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
/* |
||||
* Copyright 2002-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.context.aot; |
||||
|
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.ApplicationContextInitializer; |
||||
import org.springframework.context.ConfigurableApplicationContext; |
||||
import org.springframework.test.context.MergedContextConfiguration; |
||||
import org.springframework.test.context.SmartContextLoader; |
||||
|
||||
/** |
||||
* Strategy interface for loading an {@link ApplicationContext} for build-time |
||||
* {@linkplain #loadContextForAotProcessing AOT processing} as well as run-time |
||||
* {@linkplain #loadContextForAotRuntime AOT execution} for an integration test |
||||
* managed by the Spring TestContext Framework. |
||||
* |
||||
* <p>As of Spring Framework 6.0, AOT infrastructure requires that an {@code AotContextLoader} |
||||
* create a {@link org.springframework.context.support.GenericApplicationContext |
||||
* GenericApplicationContext} for both build-time processing and run-time execution. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 6.0 |
||||
*/ |
||||
public interface AotContextLoader extends SmartContextLoader { |
||||
|
||||
/** |
||||
* Load a new {@link ApplicationContext} for AOT build-time processing based |
||||
* on the supplied {@link MergedContextConfiguration}, configure the context, |
||||
* and return the context. |
||||
* <p>In contrast to {@link #loadContext(MergedContextConfiguration)}, this |
||||
* method must <strong>not</strong> |
||||
* {@linkplain org.springframework.context.ConfigurableApplicationContext#refresh() |
||||
* refresh} the {@code ApplicationContext} or |
||||
* {@linkplain org.springframework.context.ConfigurableApplicationContext#registerShutdownHook() |
||||
* register a JVM shutdown hook} for it. Otherwise, this method should implement |
||||
* behavior identical to {@link #loadContext(MergedContextConfiguration)}. |
||||
* @param mergedConfig the merged context configuration to use to load the |
||||
* application context |
||||
* @return a new {@code GenericApplicationContext} |
||||
* @throws Exception if context loading failed |
||||
* @see #loadContextForAotRuntime(MergedContextConfiguration, ApplicationContextInitializer) |
||||
*/ |
||||
ApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig) throws Exception; |
||||
|
||||
/** |
||||
* Load a new {@link ApplicationContext} for AOT run-time execution based on |
||||
* the supplied {@link MergedContextConfiguration} and |
||||
* {@link ApplicationContextInitializer}. |
||||
* <p>This method must instantiate, initialize, and |
||||
* {@linkplain org.springframework.context.ConfigurableApplicationContext#refresh() |
||||
* refresh} the {@code ApplicationContext}. |
||||
* @param mergedConfig the merged context configuration to use to load the |
||||
* application context |
||||
* @param initializer the {@code ApplicationContextInitializer} that should |
||||
* be applied to the context in order to recreate bean definitions |
||||
* @return a new {@code GenericApplicationContext} |
||||
* @throws Exception if context loading failed |
||||
* @see #loadContextForAotProcessing(MergedContextConfiguration) |
||||
*/ |
||||
ApplicationContext loadContextForAotRuntime(MergedContextConfiguration mergedConfig, |
||||
ApplicationContextInitializer<ConfigurableApplicationContext> initializer) throws Exception; |
||||
|
||||
} |
||||
Loading…
Reference in new issue