Browse Source

Consider primary repository definition in Repositories when created Repositories using ApplicationContext.

Closes #1583.
Original pull request: #465.
2.4.x
Mark Paluch 5 years ago
parent
commit
180c640f54
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 19
      src/main/java/org/springframework/data/repository/support/Repositories.java

19
src/main/java/org/springframework/data/repository/support/Repositories.java

@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanFactoryUtils; @@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.repository.core.EntityInformation;
@ -276,10 +277,20 @@ public class Repositories implements Iterable<Class<?>> { @@ -276,10 +277,20 @@ public class Repositories implements Iterable<Class<?>> {
if (repositoryBeanNames.containsKey(type)) {
Boolean presentAndPrimary = beanFactory //
.filter(ConfigurableListableBeanFactory.class::isInstance) //
.map(ConfigurableListableBeanFactory.class::cast) //
.map(it -> it.getBeanDefinition(name)) //
Optional<ConfigurableListableBeanFactory> factoryToUse = this.beanFactory.map(it -> {
if (it instanceof ConfigurableListableBeanFactory) {
return (ConfigurableListableBeanFactory) it;
}
if (it instanceof ConfigurableApplicationContext) {
return ((ConfigurableApplicationContext) it).getBeanFactory();
}
return null;
});
Boolean presentAndPrimary = factoryToUse.map(it -> it.getBeanDefinition(name)) //
.map(BeanDefinition::isPrimary) //
.orElse(false);

Loading…
Cancel
Save