|  | 
| 35 | 35 | import org.springframework.context.support.StaticApplicationContext; | 
| 36 | 36 | import org.springframework.core.Ordered; | 
| 37 | 37 | import org.springframework.core.ResolvableType; | 
|  | 38 | +import org.springframework.core.annotation.Order; | 
| 38 | 39 | import org.springframework.scheduling.support.TaskUtils; | 
| 39 | 40 | import org.springframework.tests.sample.beans.TestBean; | 
| 40 | 41 | 
 | 
| @@ -168,6 +169,19 @@ public void orderedListeners() { | 
| 168 | 169 | 		smc.multicastEvent(new MyOtherEvent(this)); | 
| 169 | 170 | 	} | 
| 170 | 171 | 
 | 
|  | 172 | +	@Test | 
|  | 173 | +	public void orderedListenersWithAnnotation() { | 
|  | 174 | +		MyOrderedListener3 listener1 = new MyOrderedListener3(); | 
|  | 175 | +		MyOrderedListener4 listener2 = new MyOrderedListener4(listener1); | 
|  | 176 | + | 
|  | 177 | +		SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster(); | 
|  | 178 | +		smc.addApplicationListener(listener2); | 
|  | 179 | +		smc.addApplicationListener(listener1); | 
|  | 180 | + | 
|  | 181 | +		smc.multicastEvent(new MyEvent(this)); | 
|  | 182 | +		smc.multicastEvent(new MyOtherEvent(this)); | 
|  | 183 | +	} | 
|  | 184 | + | 
| 171 | 185 | 	@Test | 
| 172 | 186 | 	@SuppressWarnings("unchecked") | 
| 173 | 187 | 	public void proxiedListeners() { | 
| @@ -396,4 +410,31 @@ public void onApplicationEvent(ApplicationEvent event) { | 
| 396 | 410 | 		} | 
| 397 | 411 | 	} | 
| 398 | 412 | 
 | 
|  | 413 | +	@Order(5) | 
|  | 414 | +	public static class MyOrderedListener3 implements ApplicationListener<ApplicationEvent> { | 
|  | 415 | + | 
|  | 416 | +		public final Set<ApplicationEvent> seenEvents = new HashSet<ApplicationEvent>(); | 
|  | 417 | + | 
|  | 418 | +		@Override | 
|  | 419 | +		public void onApplicationEvent(ApplicationEvent event) { | 
|  | 420 | +			this.seenEvents.add(event); | 
|  | 421 | +		} | 
|  | 422 | + | 
|  | 423 | +	} | 
|  | 424 | + | 
|  | 425 | +	@Order(50) | 
|  | 426 | +	public static class MyOrderedListener4 implements ApplicationListener<MyEvent> { | 
|  | 427 | + | 
|  | 428 | +		private final MyOrderedListener3 otherListener; | 
|  | 429 | + | 
|  | 430 | +		public MyOrderedListener4(MyOrderedListener3 otherListener) { | 
|  | 431 | +			this.otherListener = otherListener; | 
|  | 432 | +		} | 
|  | 433 | + | 
|  | 434 | +		@Override | 
|  | 435 | +		public void onApplicationEvent(MyEvent event) { | 
|  | 436 | +			assertTrue(otherListener.seenEvents.contains(event)); | 
|  | 437 | +		} | 
|  | 438 | +	} | 
|  | 439 | + | 
| 399 | 440 | } | 
0 commit comments