Affects: Spring Boot 2.2.0.M3
If we publish the events within the transactional reactive methods, for example:
@Transactional
public Mono<Model> create(Model model, ModelEvent.Type type) {
return repo.save(model)
.doOnSuccess(m -> publisher.publishEvent(new ModelEvent(m, type)));
}
then IllegalStateException
is raised with a message:
Specified transaction manager is not a PlatformTransactionManager: org.springframework.data.mongodb.ReactiveMongoTransactionManager
if the 'event listener' method has @Transactional
annotation (with MANDATORY parameter, for example, to check if we are really in the existent transaction):
@Transactional(propagation = Propagation.MANDATORY)
@EventListener(condition = "#event.withTransactional()")
public void handleEventWithTransactional(ModelEvent event) {
log.info("[i] Handled event: {}, with transactional", event.getModel());
}
Detailed demo is here.
Comment From: snicoll
Unfortunately, what you're trying to do is not supported. See the note in the reference documentation. Using @EventListener
the way you do and expect to run in the transaction is not accurate as the way events are fired can be asynchronous (which is why @TransactionalEvenListener
exists in the first place).