diff --git a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListener.java b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListener.java index ff0eb0a38..b4daa79f7 100644 --- a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListener.java +++ b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListener.java @@ -40,7 +40,7 @@ import org.springframework.context.event.SmartApplicationListener; */ public class SleuthContextListener implements SmartApplicationListener { - static final Map CACHE = new ConcurrentHashMap<>(); + static final Map CACHE = new ConcurrentHashMap<>(); private static final Log log = LogFactory.getLog(SleuthContextListener.class); @@ -69,7 +69,7 @@ public class SleuthContextListener implements SmartApplicationListener { if (bf instanceof ConfigurableApplicationContext) { bf = ((ConfigurableApplicationContext) bf).getBeanFactory(); } - return CACHE.getOrDefault(bf, new SleuthContextListener()); + return CACHE.getOrDefault(bf.hashCode(), new SleuthContextListener()); } @Override @@ -90,10 +90,10 @@ public class SleuthContextListener implements SmartApplicationListener { if (context instanceof ConfigurableApplicationContext) { beanFactory = ((ConfigurableApplicationContext) context).getBeanFactory(); } - SleuthContextListener listener = CACHE.getOrDefault(beanFactory, this); + SleuthContextListener listener = CACHE.getOrDefault(beanFactory.hashCode(), this); listener.refreshed.compareAndSet(false, event instanceof ContextRefreshedEvent); listener.closed.compareAndSet(false, event instanceof ContextClosedEvent); - CACHE.put(beanFactory, listener); + CACHE.put(beanFactory.hashCode(), listener); } } diff --git a/tests/common/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListenerAccessor.java b/tests/common/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListenerAccessor.java index 649bac15a..ccd5508ad 100644 --- a/tests/common/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListenerAccessor.java +++ b/tests/common/src/main/java/org/springframework/cloud/sleuth/internal/SleuthContextListenerAccessor.java @@ -27,7 +27,7 @@ public final class SleuthContextListenerAccessor { } public static void set(BeanFactory beanFactory, boolean refreshed) { - SleuthContextListener.CACHE.put(beanFactory, + SleuthContextListener.CACHE.put(beanFactory.hashCode(), new SleuthContextListener(new AtomicBoolean(refreshed), new AtomicBoolean(false))); }