Use RootBeanDefinition consistently

Closes gh-28077
pull/28078/head
Stephane Nicoll 3 years ago
parent ae00228188
commit e0465f7357

@ -449,7 +449,7 @@ class ConditionalOnMissingBeanTests {
@Override
public void registerBeanDefinitions(AnnotationMetadata meta, BeanDefinitionRegistry registry) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(NonspecificFactoryBean.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NonspecificFactoryBean.class);
builder.addConstructorArgValue("foo");
builder.getBeanDefinition().setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, ExampleBean.class);
registry.registerBeanDefinition("exampleBeanFactoryBean", builder.getBeanDefinition());
@ -467,7 +467,7 @@ class ConditionalOnMissingBeanTests {
@Override
public void registerBeanDefinitions(AnnotationMetadata meta, BeanDefinitionRegistry registry) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(NonspecificFactoryBean.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NonspecificFactoryBean.class);
builder.addConstructorArgValue("foo");
builder.getBeanDefinition().setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, ExampleBean.class.getName());
registry.registerBeanDefinition("exampleBeanFactoryBean", builder.getBeanDefinition());
@ -485,7 +485,7 @@ class ConditionalOnMissingBeanTests {
@Override
public void registerBeanDefinitions(AnnotationMetadata meta, BeanDefinitionRegistry registry) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ExampleFactoryBean.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ExampleFactoryBean.class);
builder.addConstructorArgValue("foo");
registry.registerBeanDefinition("exampleBeanFactoryBean", builder.getBeanDefinition());
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -86,8 +86,8 @@ class PropertyPlaceholderAutoConfigurationTests {
private void definePlaceholderBean(ConfigurableApplicationContext context) {
((BeanDefinitionRegistry) context.getBeanFactory()).registerBeanDefinition("placeholderBean",
BeanDefinitionBuilder.genericBeanDefinition(PlaceholderBean.class)
.addConstructorArgValue("${fruit:apple}").getBeanDefinition());
BeanDefinitionBuilder.rootBeanDefinition(PlaceholderBean.class).addConstructorArgValue("${fruit:apple}")
.getBeanDefinition());
}
@Configuration(proxyBeanMethods = false)

@ -26,7 +26,6 @@ import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.context.properties.bind.AbstractBindHandler;
@ -113,7 +112,7 @@ class ConfigurationPropertiesBinder {
private <T> BindHandler getBindHandler(Bindable<T> target, ConfigurationProperties annotation) {
List<Validator> validators = getValidators(target);
BindHandler handler = getHandler();
handler = new ConfigurationPropertiesBindHander(handler);
handler = new ConfigurationPropertiesBindHandler(handler);
if (annotation.ignoreInvalidFields()) {
handler = new IgnoreErrorsBindHandler(handler);
}
@ -193,16 +192,14 @@ class ConfigurationPropertiesBinder {
static void register(BeanDefinitionRegistry registry) {
if (!registry.containsBeanDefinition(FACTORY_BEAN_NAME)) {
AbstractBeanDefinition definition = BeanDefinitionBuilder
.genericBeanDefinition(ConfigurationPropertiesBinder.Factory.class,
ConfigurationPropertiesBinder.Factory::new)
.getBeanDefinition();
BeanDefinition definition = BeanDefinitionBuilder
.rootBeanDefinition(ConfigurationPropertiesBinder.Factory.class).getBeanDefinition();
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(ConfigurationPropertiesBinder.FACTORY_BEAN_NAME, definition);
}
if (!registry.containsBeanDefinition(BEAN_NAME)) {
AbstractBeanDefinition definition = BeanDefinitionBuilder
.genericBeanDefinition(ConfigurationPropertiesBinder.class,
BeanDefinition definition = BeanDefinitionBuilder
.rootBeanDefinition(ConfigurationPropertiesBinder.class,
() -> ((BeanFactory) registry)
.getBean(FACTORY_BEAN_NAME, ConfigurationPropertiesBinder.Factory.class).create())
.getBeanDefinition();
@ -240,9 +237,9 @@ class ConfigurationPropertiesBinder {
* {@link BindHandler} to deal with
* {@link ConfigurationProperties @ConfigurationProperties} concerns.
*/
private static class ConfigurationPropertiesBindHander extends AbstractBindHandler {
private static class ConfigurationPropertiesBindHandler extends AbstractBindHandler {
ConfigurationPropertiesBindHander(BindHandler handler) {
ConfigurationPropertiesBindHandler(BindHandler handler) {
super(handler);
}

@ -108,9 +108,7 @@ public class ConfigurationPropertiesBindingPostProcessor
Assert.notNull(registry, "Registry must not be null");
if (!registry.containsBeanDefinition(BEAN_NAME)) {
BeanDefinition definition = BeanDefinitionBuilder
.rootBeanDefinition(ConfigurationPropertiesBindingPostProcessor.class,
ConfigurationPropertiesBindingPostProcessor::new)
.getBeanDefinition();
.rootBeanDefinition(ConfigurationPropertiesBindingPostProcessor.class).getBeanDefinition();
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN_NAME, definition);
}

@ -73,7 +73,7 @@ public class DatabaseInitializationDependencyConfigurer implements ImportBeanDef
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
String name = DependsOnDatabaseInitializationPostProcessor.class.getName();
if (!registry.containsBeanDefinition(name)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(
DependsOnDatabaseInitializationPostProcessor.class,
this::createDependsOnDatabaseInitializationPostProcessor);
registry.registerBeanDefinition(name, builder.getBeanDefinition());

@ -81,10 +81,8 @@ class DatabaseInitializationDependencyConfigurerTests {
void beanFactoryPostProcessorHasOrderAllowingSubsequentPostProcessorsToFineTuneDependencies() {
performDetection(Arrays.asList(MockDatabaseInitializerDetector.class,
MockedDependsOnDatabaseInitializationDetector.class), (context) -> {
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class)
.getBeanDefinition();
BeanDefinition bravo = BeanDefinitionBuilder.genericBeanDefinition(String.class)
.getBeanDefinition();
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
BeanDefinition bravo = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
context.register(DependsOnCaptor.class);
context.register(DependencyConfigurerConfiguration.class);
context.registerBeanDefinition("alpha", alpha);
@ -104,8 +102,7 @@ class DatabaseInitializationDependencyConfigurerTests {
void whenDetectorsAreCreatedThenTheEnvironmentCanBeInjected() {
performDetection(Arrays.asList(ConstructorInjectionDatabaseInitializerDetector.class,
ConstructorInjectionDependsOnDatabaseInitializationDetector.class), (context) -> {
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class)
.getBeanDefinition();
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
context.registerBeanDefinition("alpha", alpha);
context.register(DependencyConfigurerConfiguration.class);
context.refresh();
@ -117,8 +114,8 @@ class DatabaseInitializationDependencyConfigurerTests {
@Test
void whenDependenciesAreConfiguredThenBeansThatDependUponDatabaseInitializationDependUponDetectedDatabaseInitializers() {
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
BeanDefinition bravo = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
BeanDefinition bravo = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
performDetection(Arrays.asList(MockDatabaseInitializerDetector.class,
MockedDependsOnDatabaseInitializationDetector.class), (context) -> {
context.registerBeanDefinition("alpha", alpha);
@ -140,11 +137,11 @@ class DatabaseInitializationDependencyConfigurerTests {
@Test
void whenDependenciesAreConfiguredDetectedDatabaseInitializersAreInitializedInCorrectOrder() {
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
BeanDefinition bravo1 = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
BeanDefinition bravo2 = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
BeanDefinition charlie = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
BeanDefinition delta = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
BeanDefinition bravo1 = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
BeanDefinition bravo2 = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
BeanDefinition charlie = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
BeanDefinition delta = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
performDetection(
Arrays.asList(MockDatabaseInitializerDetector.class, OrderedLowestMockDatabaseInitializerDetector.class,
OrderedNearLowestMockDatabaseInitializerDetector.class,

Loading…
Cancel
Save