diff --git a/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotGenerator.java b/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotGenerator.java index c958d1bc53..1ea201fe16 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotGenerator.java +++ b/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotGenerator.java @@ -36,14 +36,15 @@ import org.springframework.javapoet.ClassName; public class ApplicationContextAotGenerator { /** - * Refresh the specified {@link GenericApplicationContext} and generate the - * necessary code to restore the state of its {@link BeanFactory}, using the - * specified {@link GenerationContext}. - * @param applicationContext the application context to handle + * Process the specified {@link GenericApplicationContext} instance + * ahead-of-time using the specified {@link GenerationContext}. + *

Return the {@link ClassName} of the {@link ApplicationContextInitializer} + * to use to restore an optimized state of the application context. + * @param applicationContext the non-refreshed application context to handle * @param generationContext the generation context to use * @return the class name of the {@link ApplicationContextInitializer} entry point */ - public ClassName generateApplicationContext(GenericApplicationContext applicationContext, + public ClassName processAheadOfTime(GenericApplicationContext applicationContext, GenerationContext generationContext) { applicationContext.refreshForAotProcessing(); DefaultListableBeanFactory beanFactory = applicationContext.getDefaultListableBeanFactory(); diff --git a/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java b/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java index c0ad60c927..0d78e6d4c0 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java @@ -186,7 +186,7 @@ class ApplicationContextAotGeneratorTests { BiConsumer, Compiled> result) { ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator(); TestGenerationContext generationContext = new TestGenerationContext(); - generator.generateApplicationContext(applicationContext, generationContext); + generator.processAheadOfTime(applicationContext, generationContext); generationContext.writeGeneratedContent(); TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled -> result.accept(compiled.getInstance(ApplicationContextInitializer.class), compiled)); diff --git a/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java b/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java index 16dd7185fb..7836ee6b13 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java @@ -63,7 +63,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { void shouldProcessRegistrarOnConfiguration() { GenericApplicationContext applicationContext = createApplicationContext( ConfigurationWithHints.class); - this.generator.generateApplicationContext(applicationContext, + this.generator.processAheadOfTime(applicationContext, this.generationContext); assertThatSampleRegistrarContributed(); } @@ -72,7 +72,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { void shouldProcessRegistrarOnBeanMethod() { GenericApplicationContext applicationContext = createApplicationContext( ConfigurationWithBeanDeclaringHints.class); - this.generator.generateApplicationContext(applicationContext, + this.generator.processAheadOfTime(applicationContext, this.generationContext); assertThatSampleRegistrarContributed(); } @@ -82,7 +82,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { GenericApplicationContext applicationContext = createApplicationContext(); applicationContext.setClassLoader( new TestSpringFactoriesClassLoader("test-runtime-hints-aot.factories")); - this.generator.generateApplicationContext(applicationContext, + this.generator.processAheadOfTime(applicationContext, this.generationContext); assertThatSampleRegistrarContributed(); } @@ -97,7 +97,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { applicationContext.setClassLoader( new TestSpringFactoriesClassLoader("test-duplicated-runtime-hints-aot.factories")); IncrementalRuntimeHintsRegistrar.counter.set(0); - this.generator.generateApplicationContext(applicationContext, + this.generator.processAheadOfTime(applicationContext, this.generationContext); RuntimeHints runtimeHints = this.generationContext.getRuntimeHints(); assertThat(runtimeHints.resources().resourceBundles().map(ResourceBundleHint::getBaseName)) @@ -109,7 +109,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests { void shouldRejectRuntimeHintsRegistrarWithoutDefaultConstructor() { GenericApplicationContext applicationContext = createApplicationContext( ConfigurationWithIllegalRegistrar.class); - assertThatThrownBy(() -> this.generator.generateApplicationContext( + assertThatThrownBy(() -> this.generator.processAheadOfTime( applicationContext, this.generationContext)) .isInstanceOf(BeanInstantiationException.class); } diff --git a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java index e448914bfa..c9056d0e92 100644 --- a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java +++ b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java @@ -109,7 +109,7 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { private void compile(GenericApplicationContext applicationContext, BiConsumer initializationResult) { ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator(); TestGenerationContext generationContext = new TestGenerationContext(); - generator.generateApplicationContext(applicationContext, generationContext); + generator.processAheadOfTime(applicationContext, generationContext); generationContext.writeGeneratedContent(); TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled -> { ApplicationContextInitializer instance = compiled.getInstance(ApplicationContextInitializer.class);