DATACMNS-609 - Improved bean definition registration for repository configuration.
The bean definitions that were registered for a repository configuration setup we registered once for every usage of the repository configuration element (annotation or XML). This caused multiple registrations of the very same bean definition which - as in case of the RepositoryInterfaceAwareBeanPostProcessor - apparently leads to performance problems in the container startup. Feedback for the latter claim is already asked for but we improved the registration setup nonetheless. Introduced a registerIfNotAlreadyRegistered(…) method on RepositoryConfigurationExtensionSupport to allow easy registration of to-b-registered-once-and-only-once beans. We now hint towards the newly introduced method in registerWithSourceAndGeneratedBeanName(…).
This commit is contained in:
@@ -23,7 +23,12 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
|
||||
@@ -60,6 +65,26 @@ public class RepositoryConfigurationExtensionSupportUnitTests {
|
||||
assertThat(extension.isStrictRepositoryCandidate(ExtendingInterface.class), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-609
|
||||
*/
|
||||
@Test
|
||||
public void registersRepositoryInterfaceAwareBeanPostProcessorOnlyOnceForMultipleConfigurations() {
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(
|
||||
annotationMetadata, EnableRepositories.class, resourceLoader, environment);
|
||||
|
||||
extension.registerBeansForRoot(beanFactory, configurationSource);
|
||||
extension.registerBeansForRoot(beanFactory, configurationSource);
|
||||
|
||||
assertThat(beanFactory.getBeanDefinitionCount(), is(1));
|
||||
}
|
||||
|
||||
static class SampleRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
|
||||
|
||||
@Override
|
||||
@@ -95,4 +120,7 @@ public class RepositoryConfigurationExtensionSupportUnitTests {
|
||||
interface StoreInterface {}
|
||||
|
||||
interface ExtendingInterface extends StoreInterface, Repository<PlainType, Long> {}
|
||||
|
||||
@EnableRepositories
|
||||
static class SampleConfiguration {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user