Closed
Description
Hi!
Description
A assume there is a bug in spring-boot-test, related to TestRestTemplate
BeanDefinition
initialization.
To be precise, class TestRestTemplateContextCustomizer#TestRestTemplateRegistrar
in it's method postProcessBeanDefinitionRegistry
calls BeanFactoryUtils#beanNamesForTypeIncludingAncestors
.
As beanNamesForTypeIncludingAncestors
says, that's method invocation can cause FactoryBean
initialization (and their dependencies, of course). And, in context of BeanDefinitionRegistryPostProcessor
this, I guess, is incorrect behavior.
Reproducing
One file reproducer is as follows:
@Configuration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SingleFileReproducerTest.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@EnableAutoConfiguration
public class SingleFileReproducerTest {
@Test
public void dummy() {}
@Component
public static class SimpleFactoryBean implements FactoryBean {
public SimpleFactoryBean(ApplicationContext context) {}
public Object getObject() { return new Object(); }
public Class<?> getObjectType() { return Object.class; }
}
}
Note, when webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT
is commented out, test passes, as there is no need for TestRestTemplate
.
Versions
- org.springframework.boot.spring-boot-starter:2.1.2.RELEASE
- org.springframework.boot.spring-boot-starter-web:2.1.2.RELEASE
- org.springframework.boot.spring-boot-starter-test:2.1.2.RELEASE
- junit.junit:4.12
- Java 1.8