You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some types of events to publish, and they have same superclass, as say:
class AEvent{
A a;
}
class ACreatingEvent extends AEvent {}
class ACreatedEvent extends AEvent {}
class ADeletedEvent extends AEvent {}
now I'm going to publish them in my AService, since they are all AEvent, so I use a ApplicationEventPublisher<AEvent>
class AService{
@Inject ApplicationEventPublisher<AEvent> publisher;
public void create(){
publisher.publishEvent(new ACreatingEvent());
//......
publisher.publishEvent(new ACreatedEvent());
}
public void delete(){
publisher.publishEvent(new ADeletedEvent());
}
}
but these events will not be send to my ApplicationEventListeners, because they are not ApplicationEventListener<AEvent> but ApplicationEventListener<ACreatingEvent>,ApplicationEventListener<ACreatedEvent>,ApplicationEventListener<ADeletedEvent>:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have some types of events to publish, and they have same superclass, as say:
now I'm going to publish them in my
AService
, since they are all AEvent, so I use aApplicationEventPublisher<AEvent>
but these events will not be send to my
ApplicationEventListener
s, because they are notApplicationEventListener<AEvent>
butApplicationEventListener<ACreatingEvent>
,ApplicationEventListener<ACreatedEvent>
,ApplicationEventListener<ADeletedEvent>
:so I have to:
@Inject
3 publishers that matches the Event type one by one.both ways are bad...
am I miss something, or is there a better way?
Beta Was this translation helpful? Give feedback.
All reactions