diff --git a/pom.xml b/pom.xml
index 6a81501ac0..f2bde14ab2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.dataspring-data-commons
- 2.3.0.BUILD-SNAPSHOT
+ 2.3.0.DATACMNS-1591-SNAPSHOTSpring Data Core
diff --git a/src/main/java/org/springframework/data/repository/config/DefaultRepositoryConfiguration.java b/src/main/java/org/springframework/data/repository/config/DefaultRepositoryConfiguration.java
index 3129d8448d..bac185780e 100644
--- a/src/main/java/org/springframework/data/repository/config/DefaultRepositoryConfiguration.java
+++ b/src/main/java/org/springframework/data/repository/config/DefaultRepositoryConfiguration.java
@@ -182,7 +182,7 @@ public Streamable getExcludeFilters() {
return configurationSource.getExcludeFilters();
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfiguration#toImplementationDetectionConfiguration(org.springframework.core.type.classreading.MetadataReaderFactory)
*/
@@ -194,7 +194,7 @@ public ImplementationDetectionConfiguration toImplementationDetectionConfigurati
return configurationSource.toImplementationDetectionConfiguration(factory);
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfiguration#toLookupConfiguration(org.springframework.core.type.classreading.MetadataReaderFactory)
*/
@@ -205,4 +205,13 @@ public ImplementationLookupConfiguration toLookupConfiguration(MetadataReaderFac
return toImplementationDetectionConfiguration(factory).forRepositoryConfiguration(this);
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.config.RepositoryConfiguration#isPrimary()
+ */
+ @Override
+ public boolean isPrimary() {
+ return definition.isPrimary();
+ }
}
diff --git a/src/main/java/org/springframework/data/repository/config/RepositoryConfiguration.java b/src/main/java/org/springframework/data/repository/config/RepositoryConfiguration.java
index 6988395394..59d68eac3a 100644
--- a/src/main/java/org/springframework/data/repository/config/RepositoryConfiguration.java
+++ b/src/main/java/org/springframework/data/repository/config/RepositoryConfiguration.java
@@ -124,10 +124,17 @@ public interface RepositoryConfiguration registerRepositoriesIn(BeanDefinitionRegist
}
AbstractBeanDefinition beanDefinition = definitionBuilder.getBeanDefinition();
+ beanDefinition.setPrimary(configuration.isPrimary());
+
String beanName = configurationSource.generateBeanName(beanDefinition);
if (LOG.isTraceEnabled()) {
@@ -190,7 +192,7 @@ public List registerRepositoriesIn(BeanDefinitionRegist
* Registers a {@link LazyRepositoryInjectionPointResolver} over the default
* {@link ContextAnnotationAutowireCandidateResolver} to make injection points of lazy repositories lazy, too. Will
* augment the {@link LazyRepositoryInjectionPointResolver}'s configuration if there already is one configured.
- *
+ *
* @param configurations must not be {@literal null}.
* @param registry must not be {@literal null}.
*/
@@ -263,7 +265,7 @@ static class LazyRepositoryInjectionPointResolver extends ContextAnnotationAutow
/**
* Returns a new {@link LazyRepositoryInjectionPointResolver} that will have its configurations augmented with the
* given ones.
- *
+ *
* @param configurations must not be {@literal null}.
* @return
*/
@@ -276,7 +278,7 @@ LazyRepositoryInjectionPointResolver withAdditionalConfigurations(
return new LazyRepositoryInjectionPointResolver(map);
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver#isLazy(org.springframework.beans.factory.config.DependencyDescriptor)
*/
diff --git a/src/test/java/org/springframework/data/repository/config/PrimaryRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/repository/config/PrimaryRepositoryIntegrationTests.java
new file mode 100644
index 0000000000..2121038c6e
--- /dev/null
+++ b/src/test/java/org/springframework/data/repository/config/PrimaryRepositoryIntegrationTests.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.repository.config;
+
+import static org.assertj.core.api.Assertions.*;
+
+import org.junit.Test;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * Integration tests for DATACMNS-1591.
+ *
+ * @author Oliver Drotbohm
+ */
+public class PrimaryRepositoryIntegrationTests {
+
+ @Test // DATACMNS-1591
+ public void returnsPrimaryInstance() {
+
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
+
+ // Two beans available but FirstRepository is the primary one
+ assertThatCode(() -> context.getBean(FirstRepository.class)).doesNotThrowAnyException();
+ }
+
+ @Configuration
+ @EnableRepositories(considerNestedRepositories = true, //
+ includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = Marker.class))
+ static class Config {}
+
+ interface Marker {}
+
+ @Primary
+ interface FirstRepository extends CrudRepository, Marker {}
+
+ interface SecondRepository extends FirstRepository