From cd2b43ae8e285a8edd009e36bdc3ed6d81bf95d0 Mon Sep 17 00:00:00 2001
From: tish <tish@candyttl.com>
Date: Thu, 25 Jan 2024 07:59:49 +0400
Subject: [PATCH] Fix several dynamic property sources

---
 .../testcontainers/properties/TestcontainersPropertySource.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java
index 1994303645ef..d52cc0c8d51b 100644
--- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java
+++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java
@@ -115,7 +115,7 @@ private static DynamicPropertyRegistry attach(Environment environment, Applicati
 		if (eventPublisher != null) {
 			propertySource.addEventPublisher(eventPublisher);
 		}
-		else if (registry != null) {
+		else if (registry != null && !registry.containsBeanDefinition(EventPublisherRegistrar.NAME)) {
 			registry.registerBeanDefinition(EventPublisherRegistrar.NAME, new RootBeanDefinition(
 					EventPublisherRegistrar.class, () -> new EventPublisherRegistrar(environment)));
 		}