@@ -124,7 +124,7 @@ public final class Neo4jTemplate implements
124124
125125 private EventSupport eventSupport ;
126126
127- private ProjectionFactory projectionFactory ;
127+ private ProjectionFactory projectionFactoryf ;
128128
129129 private Renderer renderer ;
130130
@@ -146,6 +146,11 @@ public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingCo
146146 this .neo4jMappingContext = neo4jMappingContext ;
147147 this .cypherGenerator = CypherGenerator .INSTANCE ;
148148 this .eventSupport = EventSupport .useExistingCallbacks (neo4jMappingContext , entityCallbacks );
149+ this .renderer = Renderer .getDefaultRenderer ();
150+ }
151+
152+ ProjectionFactory getProjectionFactory () {
153+ return Objects .requireNonNull (this .projectionFactoryf , "Projection support for the Neo4j template is only available when the template is a proper and fully initialized Spring bean." );
149154 }
150155
151156 @ Override
@@ -256,7 +261,7 @@ <T, R> List<R> doFind(@Nullable String cypherQuery, @Nullable Map<String, Object
256261
257262 if (resultType .isInterface ()) {
258263 return intermediaResults .stream ()
259- .map (instance -> projectionFactory .createProjection (resultType , instance ))
264+ .map (instance -> getProjectionFactory () .createProjection (resultType , instance ))
260265 .collect (Collectors .toList ());
261266 }
262267
@@ -342,23 +347,24 @@ public <T, R> R saveAs(T instance, Class<R> resultType) {
342347 return resultType .cast (save (instance ));
343348 }
344349
345- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
350+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
351+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
346352 Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (instance .getClass (), resultType ,
347- projectionFactory , neo4jMappingContext );
353+ localProjectionFactory , neo4jMappingContext );
348354
349355 T savedInstance = saveImpl (instance , pps , null );
350356 if (!resultType .isInterface ()) {
351357 @ SuppressWarnings ("unchecked" ) R result = (R ) new DtoInstantiatingConverter (resultType , neo4jMappingContext ).convertDirectly (savedInstance );
352358 return result ;
353359 }
354360 if (projectionInformation .isClosed ()) {
355- return projectionFactory .createProjection (resultType , savedInstance );
361+ return localProjectionFactory .createProjection (resultType , savedInstance );
356362 }
357363
358364 Neo4jPersistentEntity <?> entityMetaData = neo4jMappingContext .getRequiredPersistentEntity (savedInstance .getClass ());
359365 Neo4jPersistentProperty idProperty = entityMetaData .getIdProperty ();
360366 PersistentPropertyAccessor <T > propertyAccessor = entityMetaData .getPropertyAccessor (savedInstance );
361- return projectionFactory .createProjection (resultType ,
367+ return localProjectionFactory .createProjection (resultType ,
362368 this .findById (propertyAccessor .getProperty (idProperty ), savedInstance .getClass ()).get ());
363369 }
364370
@@ -542,15 +548,16 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
542548 return saveElements ;
543549 }
544550
545- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
551+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
552+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
546553
547554 Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (commonElementType , resultType ,
548- projectionFactory , neo4jMappingContext );
555+ localProjectionFactory , neo4jMappingContext );
549556
550557 List <T > savedInstances = saveAllImpl (instances , pps , null );
551558
552559 if (projectionInformation .isClosed ()) {
553- return savedInstances .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
560+ return savedInstances .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
554561 .collect (Collectors .toList ());
555562 }
556563
@@ -563,7 +570,7 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
563570 }).collect (Collectors .toList ());
564571
565572 return findAllById (ids , commonElementType )
566- .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
573+ .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
567574 .collect (Collectors .toList ());
568575 }
569576
@@ -1000,7 +1007,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
10001007 SpelAwareProxyProjectionFactory spelAwareProxyProjectionFactory = new SpelAwareProxyProjectionFactory ();
10011008 spelAwareProxyProjectionFactory .setBeanClassLoader (beanClassLoader );
10021009 spelAwareProxyProjectionFactory .setBeanFactory (beanFactory );
1003- this .projectionFactory = spelAwareProxyProjectionFactory ;
1010+ this .projectionFactoryf = spelAwareProxyProjectionFactory ;
10041011
10051012 Configuration cypherDslConfiguration = beanFactory
10061013 .getBeanProvider (Configuration .class )
@@ -1054,7 +1061,7 @@ <T, R> List<R> doSave(Iterable<R> instances, Class<T> domainType) {
10541061 Class <?> resultType = TemplateSupport .findCommonElementType (instances );
10551062
10561063 Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (domainType , resultType ,
1057- projectionFactory , neo4jMappingContext );
1064+ getProjectionFactory () , neo4jMappingContext );
10581065
10591066 NestedRelationshipProcessingStateMachine stateMachine = new NestedRelationshipProcessingStateMachine (neo4jMappingContext );
10601067 List <R > results = new ArrayList <>();
0 commit comments