Disable WebTestClientContextCustomizer after AOT processing

After AOT processing, a WebTestClient bean will be defined directly
so the context customizer that initiates its registration is not
needed.

Closes gh-32859
This commit is contained in:
Moritz Halbritter
2022-10-25 13:51:43 +02:00
parent f2c004f604
commit b014039a34
2 changed files with 98 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.test.web.reactive.server;
import java.util.Collection;
import org.springframework.aot.AotDetector;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@@ -58,6 +59,9 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
if (AotDetector.useGeneratedArtifacts()) {
return;
}
SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(mergedConfig.getTestClass(),
SpringBootTest.class);
if (springBootTest.webEnvironment().isEmbedded()) {
@@ -109,6 +113,9 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
if (AotDetector.useGeneratedArtifacts()) {
return;
}
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) this.beanFactory,
WebTestClient.class, false, false).length == 0) {
registry.registerBeanDefinition(WebTestClient.class.getName(),