Support for multiple events per method

In addition to specifying the event type to listen to via a method
parameter, any @EventListener annotated method can now alternatively
define the event type(s) to listen to via the "classes" attributes (that
is aliased to "value").

Something like

@EventListener({FooEvent.class, BarEvent.class})
public void handleFooBar() { .... }

Issue: SPR-13156
This commit is contained in:
Stephane Nicoll
2015-07-08 14:51:07 +02:00
parent ef0eb01f93
commit bf786c3176
7 changed files with 268 additions and 33 deletions

View File

@@ -7900,6 +7900,19 @@ As you can see above, the method signature actually _infer_ which even type it l
also works for nested generics as long as the actual event resolves the generics parameter you
would filter on.
If your method should listen to several events or if you want to define it with no
parameter at all, the event type(s) can also be specified on the annotation itself:
[source,java,indent=0]
[subs="verbatim,quotes"]
----
@EventListener({ContextStartedEvent.class, ContextRefreshedEvent.class})
public void handleContextStart() {
}
----
It is also possible to add additional runtime filtering via the `condition` attribute of the
annotation that defines a <<expressions,`SpEL` expression>> that should match to actually invoke
the method for a particular event.