DATAJPA-1487 - Fixed bean definition registration for JpaMetamodelCacheCleanup.
Previously, the bean definition was registered as lazy bean which caused it not to be instantiated in the first place and thus – more importantly – the disposal method not being triggered when the ApplicationContext shuts down. We now properly register it as eager bean. Related tickets: DATAJPA-1446.
This commit is contained in:
@@ -194,7 +194,7 @@ public class JpaRepositoryConfigExtension extends RepositoryConfigurationExtensi
|
||||
|
||||
}, registry, JPA_CONTEXT_BEAN_NAME, source);
|
||||
|
||||
registerLazyIfNotAlreadyRegistered(() -> new RootBeanDefinition(JPA_METAMODEL_CACHE_CLEANUP_CLASSNAME), registry,
|
||||
registerIfNotAlreadyRegistered(() -> new RootBeanDefinition(JPA_METAMODEL_CACHE_CLEANUP_CLASSNAME), registry,
|
||||
JPA_METAMODEL_CACHE_CLEANUP_CLASSNAME, source);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.jpa.util;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import javax.persistence.metamodel.Metamodel;
|
||||
|
||||
@@ -23,7 +24,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationSource;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link JpaMetamodelCacheCleanup}.
|
||||
@@ -50,4 +55,19 @@ public class JpaMetamodelCacheCleanupIntegrationTests {
|
||||
|
||||
assertThat(model).isNotSameAs(JpaMetamodel.of(metamodel));
|
||||
}
|
||||
|
||||
@Test // DATAJPA-1487, DATAJPA-1446
|
||||
public void registersCleanupBeanAsNonLazy() {
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
RepositoryConfigurationSource configurationSource = mock(RepositoryConfigurationSource.class);
|
||||
|
||||
RepositoryConfigurationExtension extension = new JpaRepositoryConfigExtension();
|
||||
extension.registerBeansForRoot(beanFactory, configurationSource);
|
||||
|
||||
String[] cleanupBeanNames = beanFactory.getBeanNamesForType(JpaMetamodelCacheCleanup.class);
|
||||
|
||||
assertThat(cleanupBeanNames.length).isEqualTo(1);
|
||||
assertThat(beanFactory.getBeanDefinition(cleanupBeanNames[0]).isLazyInit()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user