Skip to content

Commit

Permalink
Disable TestRestTemplateContextCustomizer after AOT processing
Browse files Browse the repository at this point in the history
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 spring-projectsgh-32848
  • Loading branch information
wilkinsona committed Oct 24, 2022
1 parent 605dd3d commit b78e7b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class TestRestTemplateContextCustomizer implements ContextCustomizer {
@Override
public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedContextConfiguration) {
if (AotDetector.useGeneratedArtifacts()) {
return;
}
SpringBootTest springBootTest = TestContextAnnotationUtils
.findMergedAnnotation(mergedContextConfiguration.getTestClass(), SpringBootTest.class);
if (springBootTest.webEnvironment().isEmbedded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer.TestRestTemplateRegistrar;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.test.context.MergedContextConfiguration;
Expand All @@ -48,8 +49,10 @@ void whenContextIsNotABeanDefinitionRegistryTestRestTemplateIsRegistered() {
@Test
void whenUsingAotGeneratedArtifactsTestRestTemplateIsNotRegistered() {
new ApplicationContextRunner().withSystemProperties("spring.aot.enabled:true")
.withInitializer(this::applyTestRestTemplateContextCustomizer)
.run((context) -> assertThat(context).doesNotHaveBean(TestRestTemplate.class));
.withInitializer(this::applyTestRestTemplateContextCustomizer).run((context) -> {
assertThat(context).doesNotHaveBean(TestRestTemplateRegistrar.class);
assertThat(context).doesNotHaveBean(TestRestTemplate.class);
});
}

@SuppressWarnings({ "unchecked", "rawtypes" })
Expand Down

0 comments on commit b78e7b5

Please sign in to comment.