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:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user