Spring @EventListener with two arguments

I'm looking for a way to pass two arguments to an @EventListener. I have an Event class. It looks like this:

public class Event {
    String id;
    Date timestamp;
    String data;
    String type;

The data is serialized, and the type describes how to deserialize it.

Currently, I deserialize the event data, and then publish the deserialized EventData subclass instance on via an `ApplicationEventPublisher like so:

public void listen(Event event) throws IOException {
    EventData eventData = converter.toEventData(event);

This has worked well so far, but now I need access to both the event and the data in my listeners. Is there a way to pass two arguments to an @EventListener?

1 answer

  • answered 2018-02-13 01:37 Constantin Galbenu

    I don't thing there is a way you could pass a second argument to event listeners.

    You could add an event property to the EventData base class that is populated by the converter with the original argument that is passed to it.