Spring boot CompletableFuture链中的编程事务
如何从Spring boot CompletableFuture链中的编程事务,spring-boot,java-8,spring-transactions,completable-future,Spring Boot,Java 8,Spring Transactions,Completable Future,如何从CompletableFuture链的第一步开始事务,然后在最后一步thencomose()结束事务?例如: .thenApply(r -> { // Start transaction here }) .thenCompose(r -> { }) .thenCompose(r -> { }) .thenCompose(r -> {
CompletableFuture
链的第一步开始事务,然后在最后一步thencomose()
结束事务?例如:
.thenApply(r -> {
// Start transaction here
})
.thenCompose(r -> {
})
.thenCompose(r -> {
})
.thenCompose(r -> {
//end transaction here
})
.whenComplete((r, t) -> {
});
是否可以执行编程事务?或者我必须使用
PlatformTransactionManager
?据我所知,事务不能在Spring中从一个线程传递到另一个线程,因此它们不能跨越多个线程。不确定您在这里尝试做什么,但我相信您必须确保事务处理以及该事务中的查询都在同一线程中执行。最简单的方法是在CompletableFuture
链之外进行。@didierr您能用一个例子详细解释一下吗