Skip to content

Commit e0465f7

Browse files
committed
Use RootBeanDefinition consistently
Closes gh-28077
1 parent ae00228 commit e0465f7

File tree

6 files changed

+25
-33
lines changed

6 files changed

+25
-33
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static class NonspecificFactoryBeanClassAttributeRegistrar implements ImportBean
449449

450450
@Override
451451
public void registerBeanDefinitions(AnnotationMetadata meta, BeanDefinitionRegistry registry) {
452-
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(NonspecificFactoryBean.class);
452+
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NonspecificFactoryBean.class);
453453
builder.addConstructorArgValue("foo");
454454
builder.getBeanDefinition().setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, ExampleBean.class);
455455
registry.registerBeanDefinition("exampleBeanFactoryBean", builder.getBeanDefinition());
@@ -467,7 +467,7 @@ static class NonspecificFactoryBeanStringAttributeRegistrar implements ImportBea
467467

468468
@Override
469469
public void registerBeanDefinitions(AnnotationMetadata meta, BeanDefinitionRegistry registry) {
470-
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(NonspecificFactoryBean.class);
470+
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NonspecificFactoryBean.class);
471471
builder.addConstructorArgValue("foo");
472472
builder.getBeanDefinition().setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, ExampleBean.class.getName());
473473
registry.registerBeanDefinition("exampleBeanFactoryBean", builder.getBeanDefinition());
@@ -485,7 +485,7 @@ static class FactoryBeanRegistrar implements ImportBeanDefinitionRegistrar {
485485

486486
@Override
487487
public void registerBeanDefinitions(AnnotationMetadata meta, BeanDefinitionRegistry registry) {
488-
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ExampleFactoryBean.class);
488+
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ExampleFactoryBean.class);
489489
builder.addConstructorArgValue("foo");
490490
registry.registerBeanDefinition("exampleBeanFactoryBean", builder.getBeanDefinition());
491491
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/PropertyPlaceholderAutoConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -86,8 +86,8 @@ void whenThereIsAUserDefinedPropertySourcesPlaceholderConfigurerThenItIsUsedForV
8686

8787
private void definePlaceholderBean(ConfigurableApplicationContext context) {
8888
((BeanDefinitionRegistry) context.getBeanFactory()).registerBeanDefinition("placeholderBean",
89-
BeanDefinitionBuilder.genericBeanDefinition(PlaceholderBean.class)
90-
.addConstructorArgValue("${fruit:apple}").getBeanDefinition());
89+
BeanDefinitionBuilder.rootBeanDefinition(PlaceholderBean.class).addConstructorArgValue("${fruit:apple}")
90+
.getBeanDefinition());
9191
}
9292

9393
@Configuration(proxyBeanMethods = false)

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.beans.factory.BeanFactory;
2727
import org.springframework.beans.factory.FactoryBean;
2828
import org.springframework.beans.factory.config.BeanDefinition;
29-
import org.springframework.beans.factory.support.AbstractBeanDefinition;
3029
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
3130
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3231
import org.springframework.boot.context.properties.bind.AbstractBindHandler;
@@ -113,7 +112,7 @@ private Validator getConfigurationPropertiesValidator(ApplicationContext applica
113112
private <T> BindHandler getBindHandler(Bindable<T> target, ConfigurationProperties annotation) {
114113
List<Validator> validators = getValidators(target);
115114
BindHandler handler = getHandler();
116-
handler = new ConfigurationPropertiesBindHander(handler);
115+
handler = new ConfigurationPropertiesBindHandler(handler);
117116
if (annotation.ignoreInvalidFields()) {
118117
handler = new IgnoreErrorsBindHandler(handler);
119118
}
@@ -193,16 +192,14 @@ private Consumer<PropertyEditorRegistry> getPropertyEditorInitializer() {
193192

194193
static void register(BeanDefinitionRegistry registry) {
195194
if (!registry.containsBeanDefinition(FACTORY_BEAN_NAME)) {
196-
AbstractBeanDefinition definition = BeanDefinitionBuilder
197-
.genericBeanDefinition(ConfigurationPropertiesBinder.Factory.class,
198-
ConfigurationPropertiesBinder.Factory::new)
199-
.getBeanDefinition();
195+
BeanDefinition definition = BeanDefinitionBuilder
196+
.rootBeanDefinition(ConfigurationPropertiesBinder.Factory.class).getBeanDefinition();
200197
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
201198
registry.registerBeanDefinition(ConfigurationPropertiesBinder.FACTORY_BEAN_NAME, definition);
202199
}
203200
if (!registry.containsBeanDefinition(BEAN_NAME)) {
204-
AbstractBeanDefinition definition = BeanDefinitionBuilder
205-
.genericBeanDefinition(ConfigurationPropertiesBinder.class,
201+
BeanDefinition definition = BeanDefinitionBuilder
202+
.rootBeanDefinition(ConfigurationPropertiesBinder.class,
206203
() -> ((BeanFactory) registry)
207204
.getBean(FACTORY_BEAN_NAME, ConfigurationPropertiesBinder.Factory.class).create())
208205
.getBeanDefinition();
@@ -240,9 +237,9 @@ ConfigurationPropertiesBinder create() {
240237
* {@link BindHandler} to deal with
241238
* {@link ConfigurationProperties @ConfigurationProperties} concerns.
242239
*/
243-
private static class ConfigurationPropertiesBindHander extends AbstractBindHandler {
240+
private static class ConfigurationPropertiesBindHandler extends AbstractBindHandler {
244241

245-
ConfigurationPropertiesBindHander(BindHandler handler) {
242+
ConfigurationPropertiesBindHandler(BindHandler handler) {
246243
super(handler);
247244
}
248245

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ public static void register(BeanDefinitionRegistry registry) {
108108
Assert.notNull(registry, "Registry must not be null");
109109
if (!registry.containsBeanDefinition(BEAN_NAME)) {
110110
BeanDefinition definition = BeanDefinitionBuilder
111-
.rootBeanDefinition(ConfigurationPropertiesBindingPostProcessor.class,
112-
ConfigurationPropertiesBindingPostProcessor::new)
113-
.getBeanDefinition();
111+
.rootBeanDefinition(ConfigurationPropertiesBindingPostProcessor.class).getBeanDefinition();
114112
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
115113
registry.registerBeanDefinition(BEAN_NAME, definition);
116114
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/sql/init/dependency/DatabaseInitializationDependencyConfigurer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class DatabaseInitializationDependencyConfigurer implements ImportBeanDef
7373
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
7474
String name = DependsOnDatabaseInitializationPostProcessor.class.getName();
7575
if (!registry.containsBeanDefinition(name)) {
76-
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
76+
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(
7777
DependsOnDatabaseInitializationPostProcessor.class,
7878
this::createDependsOnDatabaseInitializationPostProcessor);
7979
registry.registerBeanDefinition(name, builder.getBeanDefinition());

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/sql/init/dependency/DatabaseInitializationDependencyConfigurerTests.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ void resetMocks() {
8181
void beanFactoryPostProcessorHasOrderAllowingSubsequentPostProcessorsToFineTuneDependencies() {
8282
performDetection(Arrays.asList(MockDatabaseInitializerDetector.class,
8383
MockedDependsOnDatabaseInitializationDetector.class), (context) -> {
84-
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class)
85-
.getBeanDefinition();
86-
BeanDefinition bravo = BeanDefinitionBuilder.genericBeanDefinition(String.class)
87-
.getBeanDefinition();
84+
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
85+
BeanDefinition bravo = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
8886
context.register(DependsOnCaptor.class);
8987
context.register(DependencyConfigurerConfiguration.class);
9088
context.registerBeanDefinition("alpha", alpha);
@@ -104,8 +102,7 @@ void beanFactoryPostProcessorHasOrderAllowingSubsequentPostProcessorsToFineTuneD
104102
void whenDetectorsAreCreatedThenTheEnvironmentCanBeInjected() {
105103
performDetection(Arrays.asList(ConstructorInjectionDatabaseInitializerDetector.class,
106104
ConstructorInjectionDependsOnDatabaseInitializationDetector.class), (context) -> {
107-
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class)
108-
.getBeanDefinition();
105+
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
109106
context.registerBeanDefinition("alpha", alpha);
110107
context.register(DependencyConfigurerConfiguration.class);
111108
context.refresh();
@@ -117,8 +114,8 @@ void whenDetectorsAreCreatedThenTheEnvironmentCanBeInjected() {
117114

118115
@Test
119116
void whenDependenciesAreConfiguredThenBeansThatDependUponDatabaseInitializationDependUponDetectedDatabaseInitializers() {
120-
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
121-
BeanDefinition bravo = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
117+
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
118+
BeanDefinition bravo = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
122119
performDetection(Arrays.asList(MockDatabaseInitializerDetector.class,
123120
MockedDependsOnDatabaseInitializationDetector.class), (context) -> {
124121
context.registerBeanDefinition("alpha", alpha);
@@ -140,11 +137,11 @@ void whenDependenciesAreConfiguredThenBeansThatDependUponDatabaseInitializationD
140137

141138
@Test
142139
void whenDependenciesAreConfiguredDetectedDatabaseInitializersAreInitializedInCorrectOrder() {
143-
BeanDefinition alpha = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
144-
BeanDefinition bravo1 = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
145-
BeanDefinition bravo2 = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
146-
BeanDefinition charlie = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
147-
BeanDefinition delta = BeanDefinitionBuilder.genericBeanDefinition(String.class).getBeanDefinition();
140+
BeanDefinition alpha = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
141+
BeanDefinition bravo1 = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
142+
BeanDefinition bravo2 = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
143+
BeanDefinition charlie = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
144+
BeanDefinition delta = BeanDefinitionBuilder.rootBeanDefinition(String.class).getBeanDefinition();
148145
performDetection(
149146
Arrays.asList(MockDatabaseInitializerDetector.class, OrderedLowestMockDatabaseInitializerDetector.class,
150147
OrderedNearLowestMockDatabaseInitializerDetector.class,

0 commit comments

Comments
 (0)