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
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
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;
|
||||
@@ -48,8 +49,10 @@ class TestRestTemplateContextCustomizerTests {
|
||||
@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" })
|
||||
|
||||
Reference in New Issue
Block a user