@@ -567,7 +567,7 @@ void beanPostProcessorPublishesEvents() {
567
567
}
568
568
569
569
@ Test
570
- void initMethodPublishesEvent () {
570
+ void initMethodPublishesEvent () { // gh-25799
571
571
GenericApplicationContext context = new GenericApplicationContext ();
572
572
context .registerBeanDefinition ("listener" , new RootBeanDefinition (BeanThatListens .class ));
573
573
context .registerBeanDefinition ("messageSource" , new RootBeanDefinition (StaticMessageSource .class ));
@@ -582,7 +582,7 @@ void initMethodPublishesEvent() {
582
582
}
583
583
584
584
@ Test
585
- void initMethodPublishesAsyncEvent () {
585
+ void initMethodPublishesAsyncEvent () { // gh-25799
586
586
GenericApplicationContext context = new GenericApplicationContext ();
587
587
context .registerBeanDefinition ("listener" , new RootBeanDefinition (BeanThatListens .class ));
588
588
context .registerBeanDefinition ("messageSource" , new RootBeanDefinition (StaticMessageSource .class ));
@@ -596,6 +596,21 @@ void initMethodPublishesAsyncEvent() {
596
596
context .close ();
597
597
}
598
598
599
+ @ Test
600
+ void initMethodPublishesAsyncEventBeforeListenerInitialized () { // gh-20904
601
+ GenericApplicationContext context = new GenericApplicationContext ();
602
+ context .registerBeanDefinition ("messageSource" , new RootBeanDefinition (StaticMessageSource .class ));
603
+ context .registerBeanDefinition ("initMethod" , new RootBeanDefinition (AsyncEventPublishingInitMethod .class ));
604
+ context .registerBeanDefinition ("listener" , new RootBeanDefinition (BeanThatListens .class ));
605
+ context .refresh ();
606
+
607
+ context .publishEvent (new MyEvent (this ));
608
+ BeanThatListens listener = context .getBean (BeanThatListens .class );
609
+ assertThat (listener .getEventCount ()).isEqualTo (3 );
610
+
611
+ context .close ();
612
+ }
613
+
599
614
600
615
@ SuppressWarnings ("serial" )
601
616
public static class MyEvent extends ApplicationEvent {
0 commit comments