Skip to content

Commit 92b07ca

Browse files
committed
Exclude TestcontainersPropertySource.EventPublisherRegistrar
1 parent be9f4a8 commit 92b07ca

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/ImportTestcontainersTests.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import static org.assertj.core.api.Assertions.assertThat;
4646
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
47+
import static org.assertj.core.api.Assertions.assertThatNoException;
4748

4849
/**
4950
* Tests for {@link ImportTestcontainers}.
@@ -53,6 +54,8 @@
5354
@DisabledIfDockerUnavailable
5455
class ImportTestcontainersTests {
5556

57+
private final TestGenerationContext generationContext = new TestGenerationContext();
58+
5659
private AnnotationConfigApplicationContext applicationContext;
5760

5861
@AfterEach
@@ -144,13 +147,19 @@ void aotContributionRegistersTestcontainers() {
144147
});
145148
}
146149

150+
@Test
151+
void importTestcontainersWithDynamicPropertySourceDoNotCauseAotProcessingToFail() {
152+
this.applicationContext = new AnnotationConfigApplicationContext();
153+
this.applicationContext.register(ContainerDefinitionsWithDynamicPropertySource.class);
154+
new TestcontainersLifecycleApplicationContextInitializer().initialize(this.applicationContext);
155+
assertThatNoException().isThrownBy(() -> new ApplicationContextAotGenerator()
156+
.processAheadOfTime(this.applicationContext, this.generationContext));
157+
}
158+
147159
@SuppressWarnings("unchecked")
148160
private void compile(BiConsumer<GenericApplicationContext, Compiled> result) {
149-
TestGenerationContext generationContext = new TestGenerationContext();
150-
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(this.applicationContext,
151-
generationContext);
152-
generationContext.writeGeneratedContent();
153-
TestCompiler.forSystem().with(generationContext).compile((compiled) -> {
161+
ClassName className = processAheadOfTime();
162+
TestCompiler.forSystem().with(this.generationContext).compile((compiled) -> {
154163
GenericApplicationContext freshApplicationContext = new GenericApplicationContext();
155164
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
156165
.getInstance(ApplicationContextInitializer.class, className.toString());
@@ -160,6 +169,13 @@ private void compile(BiConsumer<GenericApplicationContext, Compiled> result) {
160169
});
161170
}
162171

172+
private ClassName processAheadOfTime() {
173+
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(this.applicationContext,
174+
this.generationContext);
175+
this.generationContext.writeGeneratedContent();
176+
return className;
177+
}
178+
163179
@ImportTestcontainers
164180
static class ImportWithoutValue {
165181

spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import org.testcontainers.containers.Container;
2727

2828
import org.springframework.beans.BeansException;
29+
import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter;
2930
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
3031
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3132
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
33+
import org.springframework.beans.factory.support.RegisteredBean;
3234
import org.springframework.beans.factory.support.RootBeanDefinition;
3335
import org.springframework.context.ApplicationEventPublisher;
3436
import org.springframework.context.ApplicationEventPublisherAware;
@@ -166,4 +168,13 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
166168

167169
}
168170

171+
static class TestcontainersEventPublisherBeanRegistrationExcludeFilter implements BeanRegistrationExcludeFilter {
172+
173+
@Override
174+
public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
175+
return EventPublisherRegistrar.NAME.equals(registeredBean.getBeanName());
176+
}
177+
178+
}
179+
169180
}

spring-boot-project/spring-boot-testcontainers/src/main/resources/META-INF/spring/aot.factories

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter=\
2-
org.springframework.boot.testcontainers.service.connection.ConnectionDetailsRegistrar.ServiceConnectionBeanRegistrationExcludeFilter
2+
org.springframework.boot.testcontainers.service.connection.ConnectionDetailsRegistrar.ServiceConnectionBeanRegistrationExcludeFilter,\
3+
org.springframework.boot.testcontainers.properties.TestcontainersPropertySource.TestcontainersEventPublisherBeanRegistrationExcludeFilter
34

45
org.springframework.aot.hint.RuntimeHintsRegistrar=\
56
org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory.ContainerConnectionDetailsFactoriesRuntimeHints

0 commit comments

Comments
 (0)