|
|
|
@ -40,6 +40,11 @@ import org.springframework.context.ApplicationEventPublisher; |
|
|
|
import org.springframework.context.ApplicationEventPublisherAware; |
|
|
|
import org.springframework.context.ApplicationEventPublisherAware; |
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
import org.springframework.context.PayloadApplicationEvent; |
|
|
|
import org.springframework.context.PayloadApplicationEvent; |
|
|
|
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
|
|
|
|
|
|
|
import org.springframework.context.event.test.self_inject.MyApplication; |
|
|
|
|
|
|
|
import org.springframework.context.event.test.self_inject.MyEventListener; |
|
|
|
|
|
|
|
import org.springframework.context.event.test.self_inject.MyEventPublisher; |
|
|
|
|
|
|
|
import org.springframework.context.support.AbstractApplicationContext; |
|
|
|
import org.springframework.context.support.GenericApplicationContext; |
|
|
|
import org.springframework.context.support.GenericApplicationContext; |
|
|
|
import org.springframework.context.support.StaticApplicationContext; |
|
|
|
import org.springframework.context.support.StaticApplicationContext; |
|
|
|
import org.springframework.context.support.StaticMessageSource; |
|
|
|
import org.springframework.context.support.StaticMessageSource; |
|
|
|
@ -271,6 +276,24 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen |
|
|
|
assertThat(listener1.seenEvents).hasSize(2); |
|
|
|
assertThat(listener1.seenEvents).hasSize(2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Regression test for <a href="https://github.com/spring-projects/spring-framework/issues/28283">issue 28283</a>, |
|
|
|
|
|
|
|
* where event listeners proxied due to e.g. |
|
|
|
|
|
|
|
* <ul> |
|
|
|
|
|
|
|
* <li>{@code @Transactional} annotations in their methods or</li> |
|
|
|
|
|
|
|
* <li>being targeted by aspects</li> |
|
|
|
|
|
|
|
* </ul> |
|
|
|
|
|
|
|
* were added to the list of application listener beans twice (both proxy and unwrapped target). |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void eventForSelfInjectedProxiedListenerFiredOnlyOnce() { |
|
|
|
|
|
|
|
String basePackage = MyApplication.class.getPackageName(); |
|
|
|
|
|
|
|
AbstractApplicationContext context = new AnnotationConfigApplicationContext(basePackage); |
|
|
|
|
|
|
|
context.getBean(MyEventPublisher.class).publishMyEvent("hello"); |
|
|
|
|
|
|
|
assertThat(MyEventListener.eventCount).isEqualTo(1); |
|
|
|
|
|
|
|
context.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testEventPublicationInterceptor() throws Throwable { |
|
|
|
public void testEventPublicationInterceptor() throws Throwable { |
|
|
|
MethodInvocation invocation = mock(); |
|
|
|
MethodInvocation invocation = mock(); |
|
|
|
|