Improve documentation for ApplicationEvents to clarify recommended usage#35335
Closed
khj68 wants to merge 1 commit into
Closed
Improve documentation for ApplicationEvents to clarify recommended usage#35335khj68 wants to merge 1 commit into
ApplicationEvents to clarify recommended usage#35335khj68 wants to merge 1 commit into
Conversation
This commit reorders and clarifies the usage instructions for ApplicationEvents to: 1. Recommend method parameter injection as the primary approach, since ApplicationEvents has a per-method lifecycle 2. Clarify that ApplicationEvents is not a general Spring bean and cannot be constructor-injected 3. Explicitly state that field injection is an alternative approach This addresses confusion where developers expect ApplicationEvents to behave like a regular Spring bean eligible for constructor injection. Closes spring-projectsgh-35297 Signed-off-by: khj68 <junthewise@gmail.com>
ApplicationEvents to clarify recommended usage
ApplicationEvents to clarify recommended usageApplicationEvents to clarify recommended usage
sbrannen
added a commit
that referenced
this pull request
Aug 20, 2025
Contributor
|
Fixed via c0b71f8 |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the Javadoc of
ApplicationEventsto better guide developers on its proper usage.Problem
The current Javadoc mentions field injection with
@Autowiredbefore method parameter injection, which creates the impression thatApplicationEventsis a regular Spring bean eligible for dependency injection. This confuses developers who then attempt to use constructor injection and find it doesn't work.Solution
Reordered and clarified the usage instructions to:
ApplicationEventshas a per-method lifecycle, this is the most appropriate usage patternApplicationEventsis not a general Spring bean - explicitly state that it's specifically designed for use within test methodsChanges
ApplicationEventsis not a general Spring beanThis helps prevent the confusion described in the linked German documentation where developers were puzzled by the inability to use constructor injection.
Closes gh-35297