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

Collections returned from @EventListener methods should result in each element being published as an individual event [SPR-12733] #17330

Closed
spring-issuemaster opened this issue Feb 19, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Feb 19, 2015

Chris Beams opened SPR-12733 and commented

@EventListener
public List<BarEvent> handleFoo(FooEvent fooEvent) {
    // handling a FooEvent results in the creation of zero or more BarEvents
    return barEvents;
}

@EventListnener
public void handleBar(BarEvent barEvent) {
    // ...
}
  • Where barEvents is null or empty, no event is published.
  • Where barEvents is non-empty and of size n, an event is published for each BarEvent element, resulting in n invocations of #handleBar.

This approach excludes (intentionally) treating a Collection returned from an @EventListener as a first-class event, for reasons of (a) reducing implementation complexit and (b) because there's not much reason to believe this is a use case anyone would want.

Should it become a desirable use case, support for binding collections as first-class events could be added (with some difficulty), but in the meantime, users always have a natural workaround: simply drop down to @Autowiring the ApplicationEventPublisher and calling #publishEvent manually. (Note that this approach does not solve the problem of erasure on its own, and users would only be able to match against the raw collection type, but that's again another issue, and not likely to be of importance to many users anyway).

The feature as suggested above should be, relatively speaking, quite straightforward to implement and should align well with the semantics that most users would expect.


Referenced from: commits 152a7b6

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 20, 2015

Chris Beams commented

That was quick! will give it a try soon. Thanks, Stéphane.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 27, 2015

Chris Beams commented

Stephane, I've just verified this new functionality works as expected. Thanks again!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 27, 2015

Stéphane Nicoll commented

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.