Prevent early initialization of factory beans in text context customizers

Until Spring Framework 5.1.15, a FactoryBean with a non-default constructor
defined via component scanning would cause an error. This behavior has changed
as of https://github.com/spring-projects/spring-framework/issues/22409.
Regardless of this change we want to ensure that we avoid triggering eager
initialisation. `SimpleFactoryBean` has been written this way so that the tests
fail if early initialization is triggered regardless of the Spring Framework version.

Fixes gh-15898
This commit is contained in:
Madhura Bhave
2019-03-20 12:28:38 -07:00
parent 274e9ede81
commit 0c2e71cd08
4 changed files with 116 additions and 4 deletions

View File

@@ -111,8 +111,8 @@ class TestRestTemplateContextCustomizer implements ContextCustomizer {
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
(ListableBeanFactory) this.beanFactory,
TestRestTemplate.class).length == 0) {
(ListableBeanFactory) this.beanFactory, TestRestTemplate.class, false,
false).length == 0) {
registry.registerBeanDefinition(TestRestTemplate.class.getName(),
new RootBeanDefinition(TestRestTemplateFactory.class));
}

View File

@@ -111,8 +111,8 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
(ListableBeanFactory) this.beanFactory,
WebTestClient.class).length == 0) {
(ListableBeanFactory) this.beanFactory, WebTestClient.class, false,
false).length == 0) {
registry.registerBeanDefinition(WebTestClient.class.getName(),
new RootBeanDefinition(WebTestClientFactory.class));
}