It seems that when we are trying to call @Transactional
methods from @Scheduled
methods, the calls simply do not occur.
The @Transactional
methods work totally fine when they are being invoked from @Controller
REST endpoints within our application.
I wrote two classes like below...
@Component
public class StartActionTransactionHelper {
@Autowired
ActionRepository repo;
@Transactional
public Mono<Void> startAction() {
repo.doAction().subscribe();
return null;
}
}
@Component
public class StartActionScheduler {
@Autowired
StartActionTransactionHelper startActionTransactionHelper;
@Scheduled(fixedDelay = 1000)
public void startActions() {
startActionTransactionHelper.startAction();
}
}
If I remove @Transactional
, then the code gets invoked, but without being in a Transaction.
Comment From: sbchaud
Found a workaround to use TransactionalOperator operator and as(operator::transactional) as below...
Reference is https://github.com/hantsy/spring-r2dbc-sample/blob/master/docs/database-client.md.
However, the fact that @Transactional does not work, I think is still an issue.
Comment From: gumanoid
Returning null
instead of Mono<Void>
feels strange. It's impossible for caller to know when method execution is finished without a Mono
to subscribe for
Comment From: snicoll
That and startActions
looks really odd to me.
@sbchaud rather than code in text, please share a small sample that we can run ourselves to reproduce the issue. You can do so by attaching a zip to this issue or push the code to a separate GitHub repository.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.