Skip to content

Commit c02dd5a

Browse files
committed
GH-2888 - Fix eager PlatformTransactionManager dependency.
Closes #2888
1 parent 6ea4e78 commit c02dd5a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import org.springframework.data.neo4j.core.mapping.SpringDataCypherDsl;
9191
import org.springframework.data.neo4j.core.mapping.callback.EventSupport;
9292
import org.springframework.data.neo4j.core.schema.TargetNode;
93+
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
9394
import org.springframework.data.neo4j.repository.NoResultException;
9495
import org.springframework.data.neo4j.repository.query.QueryFragments;
9596
import org.springframework.data.neo4j.repository.query.QueryFragmentsAndParameters;
@@ -1100,8 +1101,10 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
11001101
this.renderer = Renderer.getRenderer(cypherDslConfiguration);
11011102
this.elementIdOrIdFunction = SpringDataCypherDsl.elementIdOrIdFunction.apply(cypherDslConfiguration.getDialect());
11021103
this.cypherGenerator.setElementIdOrIdFunction(elementIdOrIdFunction);
1103-
this.transactionTemplate = new TransactionTemplate(beanFactory.getBean(PlatformTransactionManager.class));
1104-
this.transactionTemplateReadOnly = new TransactionTemplate(beanFactory.getBean(PlatformTransactionManager.class), readOnlyTransactionDefinition);
1104+
1105+
PlatformTransactionManager transactionManager = beanFactory.getBeanProvider(PlatformTransactionManager.class).getIfUnique(() -> beanFactory.getBean(Neo4jTransactionManager.class));
1106+
this.transactionTemplate = new TransactionTemplate(transactionManager);
1107+
this.transactionTemplateReadOnly = new TransactionTemplate(transactionManager, readOnlyTransactionDefinition);
11051108
}
11061109

11071110
// only used for the CDI configuration

src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.springframework.data.neo4j.core.mapping.SpringDataCypherDsl;
6868
import org.springframework.data.neo4j.core.mapping.callback.ReactiveEventSupport;
6969
import org.springframework.data.neo4j.core.schema.TargetNode;
70+
import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager;
7071
import org.springframework.data.neo4j.repository.query.QueryFragments;
7172
import org.springframework.data.neo4j.repository.query.QueryFragmentsAndParameters;
7273
import org.springframework.data.projection.ProjectionFactory;
@@ -1181,8 +1182,10 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
11811182
this.renderer = Renderer.getRenderer(cypherDslConfiguration);
11821183
this.elementIdOrIdFunction = SpringDataCypherDsl.elementIdOrIdFunction.apply(cypherDslConfiguration.getDialect());
11831184
this.cypherGenerator.setElementIdOrIdFunction(elementIdOrIdFunction);
1184-
this.transactionalOperatorReadOnly = TransactionalOperator.create(beanFactory.getBean(ReactiveTransactionManager.class), readOnlyTransactionDefinition);
1185-
this.transactionalOperator = TransactionalOperator.create(beanFactory.getBean(ReactiveTransactionManager.class));
1185+
ReactiveTransactionManager reactiveTransactionManager = beanFactory.getBeanProvider(ReactiveTransactionManager.class)
1186+
.getIfUnique(() -> beanFactory.getBean(ReactiveNeo4jTransactionManager.class));
1187+
this.transactionalOperatorReadOnly = TransactionalOperator.create(reactiveTransactionManager, readOnlyTransactionDefinition);
1188+
this.transactionalOperator = TransactionalOperator.create(reactiveTransactionManager);
11861189
}
11871190

11881191
@Override

0 commit comments

Comments
 (0)