0

The method of the @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) annotation will not be called. In the older version 3.0.6 it is working. A small example project can be found here: https://github.com/berndklb/transactionevents Just change the spring boot version to 3.0.7 then the method of the @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) is not be called.

It looks like that inside the SimpleApplicationEventMulticaster.multicastEvent the added ApplicationListener (@TransactionalEventListener) will be filtered out in AbstractApplicationEventMulticaster.retrieveApplicationListeners() because the ApplicationListenerMethodAdapter doesn't support the eventtype.

Did the configuration changed from 3.0.6 to 3.0.7 ? Unfortunately I can't find any information about this topic.

The change between the version 3.0.6 and 3.0.7 is that inside AbstractApplicationEventMulticaster.supportsEvent(ApplicationListener listener, ResolvableType eventType, @Nullable Class sourceType) the smartListener changes from type org.springframework.context.event.GenericApplicationListenerAdapter (3.0.6) to org.springframework.context.event.ApplicationListenerMethodAdapter and the ApplicationListenerMethodAdapter.supportsEventType always returns false and so the applicationListener will not be triggered/called.

Solution

The solution is to use the classes parameter inside the TransactionalEventListener annotation.

@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true, classes = {AfterSaveEvent.class})

With this configuration ApplicationListenerMethodAdapter.supportsEventType returns true, because the declaredEventType isAssignableFrom the eventType

In Version 3.0.7 without classes attribute the declaredEventType is org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent<com.example.Test> but the eventType is org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent<?>

with the classes attribute both the declaredEventType and eventType are org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent<?>

bkb1986
  • 1
  • 1

0 Answers0