From f33f0575cb194acaf9853ae9650a7c0450a12a56 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 19 Feb 2019 15:06:40 -0500 Subject: [PATCH] GH-2752: RequestMapping: react only for our event Fixes https://github.com/spring-projects/spring-integration/issues/2752 The logic in the `IntegrationRequestMappingHandlerMapping` fully depends on the application context it has been registered with, therefore any arbitrary `ContextRefreshedEvent` doesn't fit our requirements. More over it may cause a problem with missed mappings when parent-child configuration is used. **Chery-pick to 5.1.x, 5.0.x & 4.3.x** --- .../IntegrationRequestMappingHandlerMapping.java | 12 ++++++------ ...bFluxIntegrationRequestMappingHandlerMapping.java | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/IntegrationRequestMappingHandlerMapping.java b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/IntegrationRequestMappingHandlerMapping.java index a64d64f517..32437030d4 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/IntegrationRequestMappingHandlerMapping.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/IntegrationRequestMappingHandlerMapping.java @@ -189,11 +189,6 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin return createRequestMappingInfo(requestMappingAnnotation, getCustomTypeCondition(endpoint.getClass())); } - @Override - public void afterPropertiesSet() { - // No-op in favor of onApplicationEvent - } - /** * {@link HttpRequestHandlingEndpointSupport}s may depend on auto-created * {@code requestChannel}s, so MVC Handlers detection should be postponed @@ -202,9 +197,14 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin */ @Override public void onApplicationEvent(ContextRefreshedEvent event) { - if (!this.initialized.getAndSet(true)) { + if (event.getApplicationContext().equals(getApplicationContext()) && !this.initialized.getAndSet(true)) { super.afterPropertiesSet(); } } + @Override + public void afterPropertiesSet() { + // No-op in favor of onApplicationEvent + } + } diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java index 7e35f7d849..e3a307cc80 100644 --- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java +++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -162,7 +162,7 @@ public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappi */ @Override public void onApplicationEvent(ContextRefreshedEvent event) { - if (!this.initialized.getAndSet(true)) { + if (event.getApplicationContext().equals(getApplicationContext()) && !this.initialized.getAndSet(true)) { super.afterPropertiesSet(); } }