From 147a3fdff8ef557daf5e1e8a3082c4b34e68e182 Mon Sep 17 00:00:00 2001 From: Gerrit Meier Date: Thu, 4 Apr 2024 16:01:36 +0200 Subject: [PATCH] GH-2888 - Fix eager PlatformTransactionManager dependency. Closes #2888 --- .../org/springframework/data/neo4j/core/Neo4jTemplate.java | 7 +++++-- .../data/neo4j/core/ReactiveNeo4jTemplate.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java b/src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java index 9133f818a..9e37915c9 100644 --- a/src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java +++ b/src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java @@ -90,6 +90,7 @@ import org.springframework.data.neo4j.core.mapping.RelationshipDescription; import org.springframework.data.neo4j.core.mapping.SpringDataCypherDsl; import org.springframework.data.neo4j.core.mapping.callback.EventSupport; import org.springframework.data.neo4j.core.schema.TargetNode; +import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager; import org.springframework.data.neo4j.repository.NoResultException; import org.springframework.data.neo4j.repository.query.QueryFragments; import org.springframework.data.neo4j.repository.query.QueryFragmentsAndParameters; @@ -1093,8 +1094,10 @@ public final class Neo4jTemplate implements this.renderer = Renderer.getRenderer(cypherDslConfiguration); this.elementIdOrIdFunction = SpringDataCypherDsl.elementIdOrIdFunction.apply(cypherDslConfiguration.getDialect()); this.cypherGenerator.setElementIdOrIdFunction(elementIdOrIdFunction); - this.transactionTemplate = new TransactionTemplate(beanFactory.getBean(PlatformTransactionManager.class)); - this.transactionTemplateReadOnly = new TransactionTemplate(beanFactory.getBean(PlatformTransactionManager.class), readOnlyTransactionDefinition); + + PlatformTransactionManager transactionManager = beanFactory.getBeanProvider(PlatformTransactionManager.class).getIfUnique(() -> beanFactory.getBean(Neo4jTransactionManager.class)); + this.transactionTemplate = new TransactionTemplate(transactionManager); + this.transactionTemplateReadOnly = new TransactionTemplate(transactionManager, readOnlyTransactionDefinition); } // only used for the CDI configuration diff --git a/src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java b/src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java index 3a497d96a..6d490a03e 100644 --- a/src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java +++ b/src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java @@ -67,6 +67,7 @@ import org.springframework.data.neo4j.core.mapping.RelationshipDescription; import org.springframework.data.neo4j.core.mapping.SpringDataCypherDsl; import org.springframework.data.neo4j.core.mapping.callback.ReactiveEventSupport; import org.springframework.data.neo4j.core.schema.TargetNode; +import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager; import org.springframework.data.neo4j.repository.query.QueryFragments; import org.springframework.data.neo4j.repository.query.QueryFragmentsAndParameters; import org.springframework.data.projection.ProjectionFactory; @@ -1181,8 +1182,10 @@ public final class ReactiveNeo4jTemplate implements this.renderer = Renderer.getRenderer(cypherDslConfiguration); this.elementIdOrIdFunction = SpringDataCypherDsl.elementIdOrIdFunction.apply(cypherDslConfiguration.getDialect()); this.cypherGenerator.setElementIdOrIdFunction(elementIdOrIdFunction); - this.transactionalOperatorReadOnly = TransactionalOperator.create(beanFactory.getBean(ReactiveTransactionManager.class), readOnlyTransactionDefinition); - this.transactionalOperator = TransactionalOperator.create(beanFactory.getBean(ReactiveTransactionManager.class)); + ReactiveTransactionManager reactiveTransactionManager = beanFactory.getBeanProvider(ReactiveTransactionManager.class) + .getIfUnique(() -> beanFactory.getBean(ReactiveNeo4jTransactionManager.class)); + this.transactionalOperatorReadOnly = TransactionalOperator.create(reactiveTransactionManager, readOnlyTransactionDefinition); + this.transactionalOperator = TransactionalOperator.create(reactiveTransactionManager); } @Override