@@ -123,7 +123,7 @@ public final class Neo4jTemplate implements
123123
124124 private EventSupport eventSupport ;
125125
126- private ProjectionFactory projectionFactory ;
126+ private ProjectionFactory projectionFactoryf ;
127127
128128 private Renderer renderer ;
129129
@@ -169,6 +169,11 @@ public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingCo
169169 this .neo4jMappingContext = neo4jMappingContext ;
170170 this .cypherGenerator = CypherGenerator .INSTANCE ;
171171 this .eventSupport = EventSupport .useExistingCallbacks (neo4jMappingContext , entityCallbacks );
172+ this .renderer = Renderer .getDefaultRenderer ();
173+ }
174+
175+ ProjectionFactory getProjectionFactory () {
176+ 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." );
172177 }
173178
174179 @ Override
@@ -283,7 +288,7 @@ <T, R> List<R> doFind(@Nullable String cypherQuery, @Nullable Map<String, Object
283288
284289 if (resultType .isInterface ()) {
285290 return intermediaResults .stream ()
286- .map (instance -> projectionFactory .createProjection (resultType , instance ))
291+ .map (instance -> getProjectionFactory () .createProjection (resultType , instance ))
287292 .collect (Collectors .toList ());
288293 }
289294
@@ -370,23 +375,24 @@ public <T, R> R saveAs(T instance, Class<R> resultType) {
370375 return resultType .cast (save (instance ));
371376 }
372377
373- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
378+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
379+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
374380 Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (instance .getClass (), resultType ,
375- projectionFactory , neo4jMappingContext );
381+ localProjectionFactory , neo4jMappingContext );
376382
377383 T savedInstance = saveImpl (instance , pps , null );
378384 if (!resultType .isInterface ()) {
379385 @ SuppressWarnings ("unchecked" ) R result = (R ) new DtoInstantiatingConverter (resultType , neo4jMappingContext ).convertDirectly (savedInstance );
380386 return result ;
381387 }
382388 if (projectionInformation .isClosed ()) {
383- return projectionFactory .createProjection (resultType , savedInstance );
389+ return localProjectionFactory .createProjection (resultType , savedInstance );
384390 }
385391
386392 Neo4jPersistentEntity <?> entityMetaData = neo4jMappingContext .getRequiredPersistentEntity (savedInstance .getClass ());
387393 Neo4jPersistentProperty idProperty = entityMetaData .getIdProperty ();
388394 PersistentPropertyAccessor <T > propertyAccessor = entityMetaData .getPropertyAccessor (savedInstance );
389- return projectionFactory .createProjection (resultType ,
395+ return localProjectionFactory .createProjection (resultType ,
390396 this .findById (propertyAccessor .getProperty (idProperty ), savedInstance .getClass ()).get ());
391397 }
392398
@@ -570,15 +576,16 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
570576 return saveElements ;
571577 }
572578
573- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
579+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
580+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
574581
575582 Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (commonElementType , resultType ,
576- projectionFactory , neo4jMappingContext );
583+ localProjectionFactory , neo4jMappingContext );
577584
578585 List <T > savedInstances = saveAllImpl (instances , pps , null );
579586
580587 if (projectionInformation .isClosed ()) {
581- return savedInstances .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
588+ return savedInstances .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
582589 .collect (Collectors .toList ());
583590 }
584591
@@ -591,7 +598,7 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
591598 }).collect (Collectors .toList ());
592599
593600 return findAllById (ids , commonElementType )
594- .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
601+ .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
595602 .collect (Collectors .toList ());
596603 }
597604
@@ -1024,7 +1031,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
10241031 SpelAwareProxyProjectionFactory spelAwareProxyProjectionFactory = new SpelAwareProxyProjectionFactory ();
10251032 spelAwareProxyProjectionFactory .setBeanClassLoader (beanClassLoader );
10261033 spelAwareProxyProjectionFactory .setBeanFactory (beanFactory );
1027- this .projectionFactory = spelAwareProxyProjectionFactory ;
1034+ this .projectionFactoryf = spelAwareProxyProjectionFactory ;
10281035
10291036 Configuration cypherDslConfiguration = beanFactory
10301037 .getBeanProvider (Configuration .class )
@@ -1078,7 +1085,7 @@ <T, R> List<R> doSave(Iterable<R> instances, Class<T> domainType) {
10781085 Class <?> resultType = TemplateSupport .findCommonElementType (instances );
10791086
10801087 Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (domainType , resultType ,
1081- projectionFactory , neo4jMappingContext );
1088+ getProjectionFactory () , neo4jMappingContext );
10821089
10831090 NestedRelationshipProcessingStateMachine stateMachine = new NestedRelationshipProcessingStateMachine (neo4jMappingContext );
10841091 List <R > results = new ArrayList <>();
0 commit comments