mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
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:
parent
605dd3d4bd
commit
b78e7b5ac7
@ -53,6 +53,9 @@ class TestRestTemplateContextCustomizer implements ContextCustomizer {
|
|||||||
@Override
|
@Override
|
||||||
public void customizeContext(ConfigurableApplicationContext context,
|
public void customizeContext(ConfigurableApplicationContext context,
|
||||||
MergedContextConfiguration mergedContextConfiguration) {
|
MergedContextConfiguration mergedContextConfiguration) {
|
||||||
|
if (AotDetector.useGeneratedArtifacts()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
SpringBootTest springBootTest = TestContextAnnotationUtils
|
SpringBootTest springBootTest = TestContextAnnotationUtils
|
||||||
.findMergedAnnotation(mergedContextConfiguration.getTestClass(), SpringBootTest.class);
|
.findMergedAnnotation(mergedContextConfiguration.getTestClass(), SpringBootTest.class);
|
||||||
if (springBootTest.webEnvironment().isEmbedded()) {
|
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;
|
||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
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.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.support.AbstractApplicationContext;
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
import org.springframework.test.context.MergedContextConfiguration;
|
import org.springframework.test.context.MergedContextConfiguration;
|
||||||
@ -48,8 +49,10 @@ class TestRestTemplateContextCustomizerTests {
|
|||||||
@Test
|
@Test
|
||||||
void whenUsingAotGeneratedArtifactsTestRestTemplateIsNotRegistered() {
|
void whenUsingAotGeneratedArtifactsTestRestTemplateIsNotRegistered() {
|
||||||
new ApplicationContextRunner().withSystemProperties("spring.aot.enabled:true")
|
new ApplicationContextRunner().withSystemProperties("spring.aot.enabled:true")
|
||||||
.withInitializer(this::applyTestRestTemplateContextCustomizer)
|
.withInitializer(this::applyTestRestTemplateContextCustomizer).run((context) -> {
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(TestRestTemplate.class));
|
assertThat(context).doesNotHaveBean(TestRestTemplateRegistrar.class);
|
||||||
|
assertThat(context).doesNotHaveBean(TestRestTemplate.class);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
|
Loading…
Reference in New Issue
Block a user