Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactional event listener invoked like standard event listener if @EnableTransactionManagement not active #32319

Closed
odrotbohm opened this issue Feb 23, 2024 · 0 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Milestone

Comments

@odrotbohm
Copy link
Member

odrotbohm commented Feb 23, 2024

Assume this simple Boot application:

@SpringBootApplication
// @EnableTransactionManagement
public class TxEventListenerApplication {

  public static void main(String[] args) {
    var ctx = SpringApplication.run(TxEventListenerApplication.class, args);

    ctx.publishEvent(new CustomEvent());
  }

  @TransactionalEventListener
  public void onCustomEvent(CustomEvent event) {
    System.out.println("Event received!");
  }

  record CustomEvent() {}
}

This will print Event received! upon startup, despite the event listener being declared as @TransactionalEventListener and no transaction being active. That is because without @EnableTransactionManagment, the DefaultEventListenerFactory will see @EventListener present as meta-annotation and thus create a standard ApplicationListenerMethodAdapter for the method. Activating @EnableTransactionManagement, which is enabled in standard Boot applications as soon as any kind of data access technology is present, will cause the factory to be replaced by RestrictedTransactionalEventListenerFactory which then causes the additional integration with the transaction infrastructure.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 23, 2024
@jhoeller jhoeller changed the title Transactional event listener invoked like standard event listener if @EnableTransactionManagement active Transactional event listener invoked like standard event listener if @EnableTransactionManagement not active Feb 23, 2024
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 23, 2024
@jhoeller jhoeller self-assigned this Feb 23, 2024
@jhoeller jhoeller added this to the 6.2.0-M1 milestone Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants