pull/35256/head
Phillip Webb 2 years ago
parent d86e82d026
commit 3997771f6c

@ -16,6 +16,8 @@
package org.springframework.boot.testcontainers.lifecycle; package org.springframework.boot.testcontainers.lifecycle;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import org.testcontainers.lifecycle.Startable; import org.testcontainers.lifecycle.Startable;
@ -34,12 +36,12 @@ import org.springframework.context.ConfigurableApplicationContext;
public class TestcontainersLifecycleApplicationContextInitializer public class TestcontainersLifecycleApplicationContextInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> { implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private static WeakHashMap<ConfigurableApplicationContext, Boolean> applied = new WeakHashMap<>(); private static Set<ConfigurableApplicationContext> applied = Collections.newSetFromMap(new WeakHashMap<>());
@Override @Override
public void initialize(ConfigurableApplicationContext applicationContext) { public void initialize(ConfigurableApplicationContext applicationContext) {
synchronized (applied) { synchronized (applied) {
if (applied.put(applicationContext, Boolean.TRUE) == Boolean.TRUE) { if (!applied.add(applicationContext)) {
return; return;
} }
} }

Loading…
Cancel
Save