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

Add support for explicit generic type in PayloadApplicationEvent #24599

Conversation

chenqimiao
Copy link
Contributor

@chenqimiao chenqimiao commented Feb 26, 2020

This PR is to make event mechanisms better support generics.

When I publish an event which contains generics via org.springframework.context.support.AbstractApplicationContext#publishEvent(java.lang.Object, org.springframework.core.ResolvableType) , I find that corresponding listener does not get event message. Please see the unit test cases in my PR. The unit test method of named publishEventWithGeneric fail before this PR submission.
So, I think we can add a payloadType field to PayloadApplicationEvent to fix this.
In addition, this fix code also can cache the type information of the payload to improve performance.

Thank you for reading and look forward to your reply.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 26, 2020
@rstoyanchev rstoyanchev added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Feb 28, 2020
@snicoll snicoll self-assigned this Nov 30, 2021
@snicoll snicoll removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 30, 2021
@snicoll snicoll added this to the 6.0 M1 milestone Nov 30, 2021
@chenqimiao chenqimiao changed the title Support generic ApplicationEvent by improve PayloadApplicationEvent Support generic ApplicationEvent by improving PayloadApplicationEvent Dec 2, 2021
@snicoll snicoll changed the title Support generic ApplicationEvent by improving PayloadApplicationEvent Add support for explicit generic type in PayloadApplicationEvent Dec 2, 2021
@snicoll snicoll closed this in 5589e6c Dec 2, 2021
@snicoll
Copy link
Member

snicoll commented Dec 2, 2021

@chenqimiao thank you!

@chenqimiao
Copy link
Contributor Author

@snicoll My pleasure

@chenqimiao chenqimiao deleted the impove-PayloadApplicationEvent branch December 2, 2021 09:27
@chenqimiao
Copy link
Contributor Author

org.springframework.context.event.ApplicationListenerMethodAdapter#onApplicationEvent
-->
org.springframework.context.event.ApplicationListenerMethodAdapter#processEvent
-->
org.springframework.context.event.ApplicationListenerMethodAdapter#resolveArguments
-->
org.springframework.context.event.ApplicationListenerMethodAdapter#getResolvableType
-->
ResolvableType eventType = payloadEvent.getResolvableType(); // Generics may be lost, see PR test for specific cases .

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) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants