@@ -95,14 +95,14 @@ private void populateRepositoryFactoryInformation(ListableBeanFactory factory) {
95
95
96
96
for (String name : BeanFactoryUtils .beanNamesForTypeIncludingAncestors (factory , RepositoryFactoryInformation .class ,
97
97
false , false )) {
98
- cacheRepositoryFactory (name );
98
+ cacheRepositoryFactory (factory , name );
99
99
}
100
100
}
101
101
102
102
@ SuppressWarnings ("rawtypes" )
103
- private synchronized void cacheRepositoryFactory (String name ) {
103
+ private void cacheRepositoryFactory (ListableBeanFactory factory , String name ) {
104
104
105
- RepositoryFactoryInformation repositoryFactoryInformation = beanFactory . get () .getBean (name ,
105
+ RepositoryFactoryInformation repositoryFactoryInformation = factory .getBean (name ,
106
106
RepositoryFactoryInformation .class );
107
107
RepositoryInformation information = repositoryFactoryInformation .getRepositoryInformation ();
108
108
Class <?> domainType = ClassUtils .getUserClass (information .getDomainType ());
@@ -113,8 +113,21 @@ private synchronized void cacheRepositoryFactory(String name) {
113
113
typesToRegister .add (domainType );
114
114
typesToRegister .addAll (alternativeDomainTypes );
115
115
116
+ Optional <ConfigurableListableBeanFactory > beanFactory = Optional .of (factory ).map (it -> {
117
+
118
+ if (it instanceof ConfigurableListableBeanFactory ) {
119
+ return (ConfigurableListableBeanFactory ) it ;
120
+ }
121
+
122
+ if (it instanceof ConfigurableApplicationContext ) {
123
+ return ((ConfigurableApplicationContext ) it ).getBeanFactory ();
124
+ }
125
+
126
+ return null ;
127
+ });
128
+
116
129
for (Class <?> type : typesToRegister ) {
117
- cacheFirstOrPrimary (type , repositoryFactoryInformation , BeanFactoryUtils .transformedBeanName (name ));
130
+ cacheFirstOrPrimary (beanFactory , type , repositoryFactoryInformation , BeanFactoryUtils .transformedBeanName (name ));
118
131
}
119
132
}
120
133
@@ -273,6 +286,7 @@ public List<QueryMethod> getQueryMethodsFor(Class<?> domainClass) {
273
286
return getRepositoryFactoryInfoFor (domainClass ).getQueryMethods ();
274
287
}
275
288
289
+ @ Override
276
290
public Iterator <Class <?>> iterator () {
277
291
return repositoryFactoryInfos .keySet ().iterator ();
278
292
}
@@ -281,29 +295,18 @@ public Iterator<Class<?>> iterator() {
281
295
* Caches the repository information for the given domain type or overrides existing information in case the bean name
282
296
* points to a primary bean definition.
283
297
*
298
+ * @param beanFactory must not be {@literal null}.
284
299
* @param type must not be {@literal null}.
285
300
* @param information must not be {@literal null}.
286
301
* @param name must not be {@literal null}.
287
302
*/
288
303
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
289
- private void cacheFirstOrPrimary (Class <?> type , RepositoryFactoryInformation information , String name ) {
304
+ private void cacheFirstOrPrimary (Optional <ConfigurableListableBeanFactory > beanFactory , Class <?> type ,
305
+ RepositoryFactoryInformation information , String name ) {
290
306
291
307
if (repositoryBeanNames .containsKey (type )) {
292
308
293
- Optional <ConfigurableListableBeanFactory > factoryToUse = this .beanFactory .map (it -> {
294
-
295
- if (it instanceof ConfigurableListableBeanFactory ) {
296
- return (ConfigurableListableBeanFactory ) it ;
297
- }
298
-
299
- if (it instanceof ConfigurableApplicationContext ) {
300
- return ((ConfigurableApplicationContext ) it ).getBeanFactory ();
301
- }
302
-
303
- return null ;
304
- });
305
-
306
- Boolean presentAndPrimary = factoryToUse .map (it -> it .getMergedBeanDefinition (name )) //
309
+ Boolean presentAndPrimary = beanFactory .map (it -> it .getMergedBeanDefinition (name )) //
307
310
.map (BeanDefinition ::isPrimary ) //
308
311
.orElse (false );
309
312
0 commit comments