60
60
import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
61
61
import org .springframework .data .repository .query .RepositoryQuery ;
62
62
import org .springframework .data .repository .util .QueryExecutionConverters ;
63
+ import org .springframework .data .util .Lazy ;
63
64
import org .springframework .data .util .ReflectionUtils ;
64
65
import org .springframework .lang .Nullable ;
65
66
import org .springframework .transaction .interceptor .TransactionalProxy ;
@@ -101,6 +102,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
101
102
private ClassLoader classLoader ;
102
103
private QueryMethodEvaluationContextProvider evaluationContextProvider ;
103
104
private BeanFactory beanFactory ;
105
+ private Lazy <ProjectionFactory > projectionFactory ;
104
106
105
107
private final QueryCollectingQueryCreationListener collectingListener = new QueryCollectingQueryCreationListener ();
106
108
@@ -117,6 +119,7 @@ public RepositoryFactorySupport() {
117
119
this .queryPostProcessors = new ArrayList <>();
118
120
this .queryPostProcessors .add (collectingListener );
119
121
this .methodInvocationListeners = new ArrayList <>();
122
+ this .projectionFactory = createProjectionFactory ();
120
123
}
121
124
122
125
/**
@@ -144,6 +147,7 @@ public void setNamedQueries(NamedQueries namedQueries) {
144
147
@ Override
145
148
public void setBeanClassLoader (ClassLoader classLoader ) {
146
149
this .classLoader = classLoader == null ? org .springframework .util .ClassUtils .getDefaultClassLoader () : classLoader ;
150
+ this .projectionFactory = createProjectionFactory ();
147
151
}
148
152
149
153
/*
@@ -153,6 +157,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
153
157
@ Override
154
158
public void setBeanFactory (BeanFactory beanFactory ) throws BeansException {
155
159
this .beanFactory = beanFactory ;
160
+ this .projectionFactory = createProjectionFactory ();
156
161
}
157
162
158
163
/**
@@ -354,10 +359,9 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
354
359
result .addAdvice (new DefaultMethodInvokingMethodInterceptor ());
355
360
}
356
361
357
- ProjectionFactory projectionFactory = getProjectionFactory (classLoader , beanFactory );
358
362
Optional <QueryLookupStrategy > queryLookupStrategy = getQueryLookupStrategy (queryLookupStrategyKey ,
359
363
evaluationContextProvider );
360
- result .addAdvice (new QueryExecutorMethodInterceptor (information , projectionFactory , queryLookupStrategy ,
364
+ result .addAdvice (new QueryExecutorMethodInterceptor (information , getProjectionFactory () , queryLookupStrategy ,
361
365
namedQueries , queryPostProcessors , methodInvocationListeners ));
362
366
363
367
result .addAdvice (
@@ -456,6 +460,16 @@ protected List<QueryMethod> getQueryMethods() {
456
460
return collectingListener .getQueryMethods ();
457
461
}
458
462
463
+ /**
464
+ * Returns a {@link ProjectionFactory} instance.
465
+ *
466
+ * @return
467
+ * @since 2.6
468
+ */
469
+ protected ProjectionFactory getProjectionFactory () {
470
+ return projectionFactory .get ();
471
+ }
472
+
459
473
/**
460
474
* Returns the {@link EntityInformation} for the given domain class.
461
475
*
@@ -586,6 +600,10 @@ private StartupStep onEvent(ApplicationStartup applicationStartup, String name,
586
600
return step .tag ("repository" , repositoryInterface .getName ());
587
601
}
588
602
603
+ private Lazy <ProjectionFactory > createProjectionFactory () {
604
+ return Lazy .of (() -> getProjectionFactory (this .classLoader , this .beanFactory ));
605
+ }
606
+
589
607
/**
590
608
* Method interceptor that calls methods on the {@link RepositoryComposition}.
591
609
*
0 commit comments