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

Annotation-based event listener does not receive event published in @PostConstruct [SPR-15122] #19689

Closed
spring-projects-issues opened this issue Jan 10, 2017 · 1 comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 10, 2017

František Hartman opened SPR-15122 and commented

Annotation-based event listener does not receive event published in @PostConstruct, while old style interface based listener does.

See example project at https://github.com/frant-hartm/spring-application-events

One event is published in @PostConstruct method of another bean. Another event is published from main method after context is initialised. Interface based listener sees both events, annotation based sees only the second one:

Interface based sees event: MyEvent{value='from postConstruct'}
Annotation based sees event: MyEvent{value='from main'}
Interface based sees event: MyEvent{value='from main'}


Affects: 4.3.5

Reference URL: https://github.com/frant-hartm/spring-application-events

Issue Links:

@snicoll
Copy link
Member

snicoll commented Jan 4, 2024

The reason for this is that EventListenerMethodProcessor is a SmartInitializingSingleton that loops over beans in the context to determine if they have an annotated method in the afterSingletonsInstantiated phase. This essentially means that the listener is not registered (yet) in the PostConstruct phase of any bean.

IMO it is better this way as it makes things a bit more clear in terms of contracts. The annotation-based use case purely works by accident. If MyBean was processed before AnnotationBasedListener, it would not see the event either.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
@snicoll snicoll added the status: declined A suggestion or change that we don't feel we should currently apply label Jan 4, 2024
@snicoll snicoll removed this from the 6.x Backlog milestone Jan 4, 2024
snicoll added a commit that referenced this issue Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants