@ -16,8 +16,6 @@
@@ -16,8 +16,6 @@
package org.springframework.context.event ;
import java.io.Closeable ;
import java.io.IOException ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
@ -627,12 +625,13 @@ public class AnnotationDrivenEventListenerTests {
@@ -627,12 +625,13 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void missingBeanDoesntCrash ( ) {
load ( MissingEventListener . class ) ;
context . getBean ( UseMissingEventListener . class ) ;
context . getBean ( ApplicationEventMulticaster . class ) . multicastEvent ( new TestEvent ( this ) ) ;
public void missingListenerBeanIgnored ( ) {
load ( MissingEventListener . class ) ;
context . getBean ( UseMissingEventListener . class ) ;
context . getBean ( ApplicationEventMulticaster . class ) . multicastEvent ( new TestEvent ( this ) ) ;
}
private void load ( Class < ? > . . . classes ) {
List < Class < ? > > allClasses = new ArrayList < > ( ) ;
allClasses . add ( BasicConfiguration . class ) ;
@ -1087,31 +1086,32 @@ public class AnnotationDrivenEventListenerTests {
@@ -1087,31 +1086,32 @@ public class AnnotationDrivenEventListenerTests {
}
@Configuration
@Import ( { UseMissingEventListener . class } )
@Import ( UseMissingEventListener . class )
public static class MissingEventListener {
@Bean
public MyEventListener missing ( ) {
return null ;
}
@Bean
public MyEventListener missing ( ) {
return null ;
}
}
@Component
public static class MyEventListener implements Closeable {
@EventListener
public void hear ( TestEvent e ) {
throw new AssertionError ( ) ;
}
public static class MyEventListener {
@Override
public void close ( ) throws IOException { }
@EventListener
public void hear ( TestEvent e ) {
throw new AssertionError ( ) ;
}
}
public static class UseMissingEventListener {
@Inject
public UseMissingEventListener ( Optional < MyEventListener > notHere ) {
if ( notHere . isPresent ( ) ) {
throw new AssertionError ( ) ;
}
}
@Inject
public UseMissingEventListener ( Optional < MyEventListener > notHere ) {
if ( notHere . isPresent ( ) ) {
throw new AssertionError ( ) ;
}
}
}
}