diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java index 62091d2ae..990cda154 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteDefinitionLocator.java @@ -21,16 +21,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.context.ApplicationListener; import reactor.cache.CacheFlux; import reactor.core.publisher.Flux; import org.springframework.cloud.gateway.event.RefreshRoutesEvent; -import org.springframework.context.event.EventListener; /** * @author Spencer Gibb */ -public class CachingRouteDefinitionLocator implements RouteDefinitionLocator { +public class CachingRouteDefinitionLocator implements RouteDefinitionLocator, ApplicationListener { private final RouteDefinitionLocator delegate; private final Flux routeDefinitions; @@ -57,7 +57,12 @@ public class CachingRouteDefinitionLocator implements RouteDefinitionLocator { return this.routeDefinitions; } - @EventListener(RefreshRoutesEvent.class) + @Override + public void onApplicationEvent(RefreshRoutesEvent event) { + refresh(); + } + + @Deprecated /* for testing */ void handleRefresh() { refresh(); } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java index 58e6f408c..a7eda34fd 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java @@ -21,17 +21,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.context.ApplicationListener; import reactor.cache.CacheFlux; import reactor.core.publisher.Flux; import org.springframework.cloud.gateway.event.RefreshRoutesEvent; -import org.springframework.context.event.EventListener; import org.springframework.core.annotation.AnnotationAwareOrderComparator; /** * @author Spencer Gibb */ -public class CachingRouteLocator implements RouteLocator { +public class CachingRouteLocator implements RouteLocator, ApplicationListener { private final RouteLocator delegate; private final Flux routes; @@ -57,7 +57,12 @@ public class CachingRouteLocator implements RouteLocator { return this.routes; } - @EventListener(RefreshRoutesEvent.class) + @Override + public void onApplicationEvent(RefreshRoutesEvent event) { + refresh(); + } + + @Deprecated /* for testing */ void handleRefresh() { refresh(); }