Skip to content

Comments

GH-1123 - Detect events configured for externalization published outside a transaction#1456

Open
yunhobb wants to merge 1 commit intospring-projects:mainfrom
yunhobb:feature/gh-1123-warning-events-published-outside-transaction
Open

GH-1123 - Detect events configured for externalization published outside a transaction#1456
yunhobb wants to merge 1 commit intospring-projects:mainfrom
yunhobb:feature/gh-1123-warning-events-published-outside-transaction

Conversation

@yunhobb
Copy link

@yunhobb yunhobb commented Nov 14, 2025

Summary

Events configured for externalization via @Externalized silently fail when published outside a transaction context — they are neither persisted nor externalized. This can be difficult to diagnose.

This change adds a warning log in PersistentApplicationEventMulticaster to detect this scenario and inform developers with actionable guidance.

Fixes #1123

Changes

  • Add EventExternalizationConfiguration as an optional dependency to PersistentApplicationEventMulticaster with a backward-compatible two-argument constructor overload
  • Add detectEventPublishedOutsideTransaction() that logs a warning when:
    1. No active transaction is present
    2. Transactional event listeners exist for the event
    3. The event is configured for externalization
  • Wire ObjectProvider<EventExternalizationConfiguration> through EventPublicationConfiguration and EventPublicationAutoConfiguration
  • Add Javadoc to TransactionalEventListeners.hasListeners()

Test plan

  • 4 new unit tests covering all branches:
    • Warns when externalization event published outside transaction
    • Does not warn inside an active transaction
    • Does not warn for non-externalization events
    • Does not warn when no transactional listeners exist
  • All existing module tests pass

… published outside a transaction.

Signed-off-by: yunhobb <[email protected]>
@yunhobb yunhobb force-pushed the feature/gh-1123-warning-events-published-outside-transaction branch from e38c964 to 2cc322a Compare February 20, 2026 15:06
@yunhobb yunhobb changed the title GH-1123 - Detect and warn about events configured for externalization published outside transaction context GH-1123 - Detect events configured for externalization published outside a transaction Feb 20, 2026
Supplier<Environment> environment) {
this(registry, environment, EventExternalizationConfiguration::disabled);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added new 3-arg constructor but kept the old 2-arg one to not break existing API. The old one just delegates to new one with disabled config. If you think @deprecated is needed or want different approach, please let me know.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way to verify this detection is checking log output, so I used Logback ListAppender to capture it. I see this pattern is not used in other tests in this project. If you prefer different way to test this, I'm happy to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect events to be externalized not published within a transaction

1 participant