Skip to content

Commit 0057130

Browse files
committed
Freeze configuration before invoking MBDPP instances
This commit updates refresh for AOT processing so that the configuration is frozen before invoking MergedBeanDefinitionPostProcessor instances. This makes sure that post-processed MergedBeanDefinitions are kept in cache and not lost if a component attempts to clear the metadata cache. Closes gh-28941
1 parent 0a9db7c commit 0057130

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ public void refreshForAotProcessing() {
406406
prepareBeanFactory(this.beanFactory);
407407
postProcessBeanFactory(this.beanFactory);
408408
invokeBeanFactoryPostProcessors(this.beanFactory);
409+
this.beanFactory.freezeConfiguration();
409410
PostProcessorRegistrationDelegate.invokeMergedBeanDefinitionPostProcessors(this.beanFactory);
410411
}
411412

spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,19 @@ void refreshForAotInvokesMergedBeanDefinitionPostProcessorsOnPropertyValue() {
409409
context.close();
410410
}
411411

412+
@Test
413+
void refreshForAotFreezeConfiguration() {
414+
GenericApplicationContext context = new GenericApplicationContext();
415+
context.registerBeanDefinition("test", new RootBeanDefinition(String.class));
416+
MergedBeanDefinitionPostProcessor bpp = registerMockMergedBeanDefinitionPostProcessor(context);
417+
context.refreshForAotProcessing();
418+
RootBeanDefinition mergedBeanDefinition = getBeanDefinition(context, "test");
419+
verify(bpp).postProcessMergedBeanDefinition(mergedBeanDefinition, String.class, "test");
420+
context.getBeanFactory().clearMetadataCache();
421+
assertThat(context.getBeanFactory().getMergedBeanDefinition("test")).isSameAs(mergedBeanDefinition);
422+
context.close();
423+
}
424+
412425
@Test
413426
void refreshForAotInvokesBeanPostProcessorContractOnMergedBeanDefinitionPostProcessors() {
414427
MergedBeanDefinitionPostProcessor bpp = new MergedBeanDefinitionPostProcessor() {

0 commit comments

Comments
 (0)