Method invocation skipped when @Scheduled components are invoking @Transactional methods
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.
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.
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
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.
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.
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.