diff --git a/src/main/java/org/springframework/data/repository/support/Repositories.java b/src/main/java/org/springframework/data/repository/support/Repositories.java index 606426d1c..fb1e4ac85 100644 --- a/src/main/java/org/springframework/data/repository/support/Repositories.java +++ b/src/main/java/org/springframework/data/repository/support/Repositories.java @@ -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> { if (repositoryBeanNames.containsKey(type)) { - Boolean presentAndPrimary = beanFactory // - .filter(ConfigurableListableBeanFactory.class::isInstance) // - .map(ConfigurableListableBeanFactory.class::cast) // - .map(it -> it.getBeanDefinition(name)) // + Optional 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);