When spring.main.lazy-initialization is true, the LazyInitializationBeanFactoryPostProcessor makes the JpaMetamodelCacheCleanup bean lazy, causing the cleanup to never happen. This manifests in OOMs when running lots of tests with DirtiesContext.
Adding this bean to the context:
@Bean
public static LazyInitializationExcludeFilter integrationLazyInitializationExcludeFilter() {
return (beanName, beanDefinition, beanType)
-> beanName.equals("org.springframework.data.jpa.util.JpaMetamodelCacheCleanup");
}
Works around the issue.
This issue was observed in version 3.2.11.