Skip to content

Commit b78e7b5

Browse files
committed
Disable TestRestTemplateContextCustomizer after AOT processing
After AOT processing, a TestRestTemplate bean will be defined directly so the context customizer that initiates its registration is not needed. We'd already disabled the registrar but this is insufficient in Graal 22.3 which fails fast when the customizer tries to reference the registrar. Fixes gh-32848
1 parent 605dd3d commit b78e7b5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplateContextCustomizer.java

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class TestRestTemplateContextCustomizer implements ContextCustomizer {
5353
@Override
5454
public void customizeContext(ConfigurableApplicationContext context,
5555
MergedContextConfiguration mergedContextConfiguration) {
56+
if (AotDetector.useGeneratedArtifacts()) {
57+
return;
58+
}
5659
SpringBootTest springBootTest = TestContextAnnotationUtils
5760
.findMergedAnnotation(mergedContextConfiguration.getTestClass(), SpringBootTest.class);
5861
if (springBootTest.webEnvironment().isEmbedded()) {

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateContextCustomizerTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.boot.test.context.SpringBootTest;
2424
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2525
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
26+
import org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer.TestRestTemplateRegistrar;
2627
import org.springframework.context.ConfigurableApplicationContext;
2728
import org.springframework.context.support.AbstractApplicationContext;
2829
import org.springframework.test.context.MergedContextConfiguration;
@@ -48,8 +49,10 @@ void whenContextIsNotABeanDefinitionRegistryTestRestTemplateIsRegistered() {
4849
@Test
4950
void whenUsingAotGeneratedArtifactsTestRestTemplateIsNotRegistered() {
5051
new ApplicationContextRunner().withSystemProperties("spring.aot.enabled:true")
51-
.withInitializer(this::applyTestRestTemplateContextCustomizer)
52-
.run((context) -> assertThat(context).doesNotHaveBean(TestRestTemplate.class));
52+
.withInitializer(this::applyTestRestTemplateContextCustomizer).run((context) -> {
53+
assertThat(context).doesNotHaveBean(TestRestTemplateRegistrar.class);
54+
assertThat(context).doesNotHaveBean(TestRestTemplate.class);
55+
});
5356
}
5457

5558
@SuppressWarnings({ "unchecked", "rawtypes" })

0 commit comments

Comments
 (0)