Prevent duplicate registration of TestRestTemplate after AOT processing

Closes gh-32542
This commit is contained in:
Andy Wilkinson
2022-10-06 12:56:38 +01:00
parent 188cac6540
commit 68e4aa232b
2 changed files with 23 additions and 7 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.boot.test.web.client;
import org.springframework.aot.AotDetector;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@@ -103,6 +104,9 @@ class TestRestTemplateContextCustomizer implements ContextCustomizer {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
if (AotDetector.useGeneratedArtifacts()) {
return;
}
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) this.beanFactory,
TestRestTemplate.class, false, false).length == 0) {
registry.registerBeanDefinition(TestRestTemplate.class.getName(),