Patrick Beaumont opened SPR-15346 and commented
As seen in page Better application events in Spring Framework 4.2, we cannot publish event without creating a class that would resolve generics parameters, due to type erasure.
It seems that it might be resolved with the ResolvableType, in the PayloadApplicationevent#getResolvableType().
Currently, we have
@Override
public ResolvableType getResolvableType() {
return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(getPayload()));
}
which resolves correctly events in the form
MyEvent extends GenericMyEvent<T>
With something like the following, I was able to have it work in our project:
@Override
public ResolvableType getResolvableType() {
return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forClassWithGenerics(payloadClass, ResolvableType.forInstance(payloadEntity)));
}
Affects: 4.3.5
1 votes, 2 watchers
Comment From: spring-projects-issues
gtxx commented
+1 for this feature. In my project, there are dozens of entity class, and I'd like to publish entity-create/ entity-update/ entity-delete event for each entity. With this feature, I can publish generic event in generic service, that will reduce a lot boilerplate code.
Comment From: snicoll
It's hard to understand what you mean as you didn't share where payloadClass
and payloadEntity
come from. We've improved this area of the framework recently, see #24599.
I am going to close this but if you believe this is still a problem and can share more details we can reopen of course.